本帖最后由 u014774352 于 2014-04-18 17:30:52 编辑

解决方案 »

  1.   

    $startDate = '2014-01-01';
    $startTime = strtotime($startDate);
    for($m = 0;$m < 12;$m++){
    $nowTime = strtotime('+'.$m.' month',$startTime);
    $w = date('w',$nowTime);
    $t = date('t',$nowTime);
    for($i = 1;$i < $w;$i++){
    echo '* ';
    }
    for($i = 1;$i <= $t;$i++){
    echo "$i ";
    }
    $s = 43 - $w - $t;
    for($i = 1;$i <= $s;$i++){
    echo "* ";
    }
    echo '<br />';
    }
      

  2.   


      $nowTime = strtotime('+'.$m.' month',$startTime);
        $w = date('w',$nowTime);
        $t = date('t',$nowTime);
    我看不懂。。这3句是什么意思
      

  3.   

    <html>
    <meta charset="utf-8"/>
    <head>
    <style>
    #tc_calendar{width:250px;}
    #tc_title{height:33px;line-height:33px;text-align:right;overflow:hidden;float:left;}
    #tc_title strong{font-weight:bold;font-size:14px;}
    #tc_calendar{border-collapse:collapse;}
    #tc_calendar td{text-align:center;width:35px;height:20px;line-height:20px;background-color:#efefef;border-bottom:1px solid #fff;border-right:1px solid #fff;}
    #tc_calendar .even td{background-color:#e6e6e6;}
    #tc_calendar td .current{display:block;background-color:#f60;color:#fff;}
    #tc_calendar .current{background-color:#f60!important;color:#fff;}
    #tc_week td{color:#fff;background-color:#373737;}
    </style>
    </head>
    <body>
    <?php
    $mdays=date("t");    //当月总天数
    $datenow=date("j");  //当日日期
    $monthnow=date("n"); //当月月份
    $yearnow=date("Y");  //当年年份
    //计算当月第一天是星期几
    $wk1st=date("w",mktime(0,0,0,$monthnow,1,$yearnow));
    $trnum=ceil(($mdays+$wk1st)/7); //计算表格行数
    //以下是表格字串
    $tabstr="<table id=tc_calendar><tr id=tc_week><td>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td></tr>";
    for($i=0;$i<$trnum;$i++) {
       $tabstr.="<tr class=even>";
       for($k=0;$k<7;$k++) { //每行七个单元格
          $tabidx=$i*7+$k; //取得单元格自身序号
          //若单元格序号小于当月第一天的星期数($wk1st)或大于(月总数+$wk1st)
          //只填写空格,反之,写入日期
          ($tabidx<$wk1st or $tabidx>$mdays+$wk1st-1) ? $dayecho="&nbsp" : $dayecho=$tabidx-$wk1st+1;
          //突出标明今日日期
          // $dayecho="<span style=\"background-color:red;color:#fff;\">$dayecho</span>";
          if($dayecho==$datenow){$todaybg = " class=current";}
          else{$todaybg = "";}
          $tabstr.="<td".$todaybg.">$dayecho</td>";
       }
       $tabstr.="</tr>";
    }
    $tabstr.="</table>";
    ?>
    <div id="tc_calendardiv">
    <div id="tc_title">
    <?php echo date("Y");?>年<strong> <?php echo date("m");?>月</strong>
    </div>
    <?php echo $tabstr;?>
    </div>
    </body>
    </html>
      

  4.   


      $nowTime = strtotime('+'.$m.' month',$startTime);
        $w = date('w',$nowTime);
        $t = date('t',$nowTime);
    我看不懂。。这3句是什么意思$startTime //是2014-01-01日的时间戳  $nowTime = strtotime('+'.$m.' month',$startTime);// 加 m个月的时间戳
        $w = date('w',$nowTime);//日期对应的星期几
        $t = date('t',$nowTime);//本月天数
      

  5.   

    厉害,我从未想过用php做日历,因为js做的日历满天飞,想怎么用怎么用。佩服大家的精神