日历格式模板

//格式化提交数据
function post_input($data){
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
public function test(){
    //设置中国时区时间
    if (function_exists('date_default_timezone_set')){
        date_default_timezone_set('PRC');
    }
    //判断获取
    $year = isset($_GET['y']) ? post_input($_GET['y']): date('Y');
    //当前月份
    $month = isset($_GET['m']) ? post_input($_GET['m']): date('m');
    //当前日子
    $day = isset($_GET['d']) ? post_input($_GET['d']): date('d');

    
    //设置月份转化年份规则
    if ($month > 12){
        $month = 1;
        $year++;
    }elseif ($month < 1){
        $month = 12;
        $year--;
    }
    
    //获取每个月一号的时间戳
    $t = strtotime("$year-$month-1");
    //一月的结束时间
    $last = date('t',strtotime("-1 month",$t));
    
    $start = date('w',$t) ? range($last - date('w',$t) + 1,$last) : range($last-6,$last);
    
    //当前月的天数
    $days = range(1,date('t',$t));
    
    $end = range(1,6 * 7 - count($start) - count($days));
  
    //遍历组装html
    $daytables = "<tr>";
    $w = 1;
    for ($i = 0;$i < count($start);$i++){
        if ($w % 7 == 0){
            
            $daytables .= "<td data-title='last'>$start[$i]</td></tr><tr>";
        } else {
            
            $daytables .= "<td data-title='last'>$start[$i]</td>";
        }
        $w++;
    }
    for ($i = 0;$i < count($days);$i++){
        if($w % 7 == 0){
            $daytables .="<td>$days[$i]</td></tr><tr>";
            
        }else{
            $daytables .= "<td>$days[$i]</td>";
            
        }
        $w++;
    }
    
    for ($i = 0;$i < count($end);$i++){
        if($w % 7 == 0){
            $daytables .="<td style='color:#898989' data-title='last'>$end[$i]</td></tr><tr>";
            
        }else{
            $daytables .= "<td style='color:#898989' data-title='last'>$end[$i]</td>";
            //print_r($end[$i]);exit;
        }
        $w++;
    }
    
    $daytables .= "<tr/></tbody></table>";
    $this->view->assign('daytables', $daytables);
    return $this->view->fetch();
}
<style>
    .basicinfo {
        margin: 15px 0;
    }

    .basicinfo .row > .col-xs-4 {
        padding-right: 0;
    }

    .basicinfo .row > div {
        margin: 5px 0;
    }

     .table tr th  {
         text-align: center;
     	color:#1d89cf;
     	background-color:#D6E9F1;
     }
 </style>
<div id="content-container" class="container">
   
                    <table class="table table-bordered table-condensed" align="center">
    <thead>
    </thead>
    <tbody>
    <tr>
        <td class="red"></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td class="red"></td>
    </tr>
    {$daytables}
    </tbody>
</table>
</div>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值