国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PHP development to create a simple calendar and CLASS class

We explained earlier the

threshold method, which generates each boundary value of the calendar

caculate method, calculates the number of days and style of the calendar

draw method, draws the table, and sets tr and td in the table

In this section we encapsulate them into a Calendar class and then reference it on the front-end page. You can call this class when doing other similar projects in the future.

This class file is created with the name calendar.php.

<?php 
class Calendar {
   /*
    * @deprecated 生成日歷的各個邊界值
    * @param string $year
    * @param string $month
    * @return array
    */
   function threshold($year, $month) {
      $firstDay = mktime(0, 0, 0, $month, 1, $year);  //mktime() 函數(shù)返回日期的 UNIX 時間戳。
      $lastDay = strtotime('+1 month -1 day', $firstDay);
      //取得天數(shù)  
      $days = date("t", $firstDay);
      //取得第一天是星期幾
      $firstDayOfWeek = date("N", $firstDay);
      //獲得最后一天是星期幾
      $lastDayOfWeek = date('N', $lastDay);
      
      //上一個月最后一天
      $lastMonthDate = strtotime('-1 day', $firstDay); //strtotime() 函數(shù)將任何英文文本的日期或時間描述解析為 Unix 時間戳
      $lastMonthOfLastDay = date('d', $lastMonthDate);
      //下一個月第一天
      $nextMonthDate = strtotime('+1 day', $lastDay);
      $nextMonthOfFirstDay = strtotime('+1 day', $lastDay);
      
      //日歷的第一個日期
      if($firstDayOfWeek == 7) {
         $firstDate = $firstDay;
      }else {
         $firstDate = strtotime('-' . $firstDayOfWeek . ' day', $firstDay);
      }
      //日歷的最后一個日期
      if($lastDayOfWeek == 6) {
         $lastDate = $lastDay;
      }elseif($lastDayOfWeek == 7) {
         $lastDate = strtotime('+6 day', $lastDay);
      }else {
         $lastDate = strtotime('+' . (6 - $lastDayOfWeek) . ' day', $lastDay);
      }
      return array(
            'days' => $days, 
            'firstDayOfWeek' => $firstDayOfWeek, 
            'lastDayOfWeek' => $lastDayOfWeek,
            'lastMonthOfLastDay' => $lastMonthOfLastDay,
            'firstDate' => $firstDate,
            'lastDate' => $lastDate,
            'year' => $year,
            'month' => $month
      );
   }
   /*
    * @author Pwstrick
    * @param array $calendar 通過threshold方法計(jì)算后的數(shù)據(jù)
    * @deprecated 計(jì)算日歷的天數(shù)與樣式
    */
   function caculate($calendar) {
      $days = $calendar['days'];
      $firstDayOfWeek = $calendar['firstDayOfWeek'];//本月第一天的星期
      $lastDayOfWeek = $calendar['lastDayOfWeek'];//本月最后一天的星期
      $lastMonthOfLastDay = $calendar['lastMonthOfLastDay'];//上個月的最后一天
      $year = $calendar['year'];
      $month = $calendar['month'];
      
      $dates = array();
      if($firstDayOfWeek != 7) {
         $lastDays = array();
         $current = $lastMonthOfLastDay;//上個月的最后一天
         for ($i = 0; $i < $firstDayOfWeek; $i++) {
            array_push($lastDays, $current);//添加上一個月的日期天數(shù)
            $current--;
         }
         $lastDays = array_reverse($lastDays);//反序
         foreach ($lastDays as $index => $day) {
            array_push($dates, array('day' => $day, 'tdclass' => ($index ==0 ?'rest':''), 'pclass' => 'outter'));
         }
      }
      
      //本月日歷信息
      for ($i = 1; $i <= $days; $i++) {
         $isRest = $this->_checkIsRest($year, $month, $i);
         //判斷是否是休息天
         array_push($dates, array('day' => $i, 'tdclass' => ($isRest ?'rest':''), 'pclass' => ''));
      }
      
      //下月日歷信息
      if($lastDayOfWeek == 7) {//最后一天是星期日
         $length = 6;
      }
      elseif($lastDayOfWeek == 6) {//最后一天是星期六
         $length = 0;
      }else {
         $length = 6 - $lastDayOfWeek;
      }
      for ($i = 1; $i <= $length; $i++) {
         array_push($dates, array('day' => $i, 'tdclass' => ($i==$length ?'rest':''), 'pclass' => 'outter'));
      }
      
      return $dates;
   }
   
   /*
    * @author Pwstrick
    * @deprecated 判斷是否是休息天
    */
   private function _checkIsRest($year, $month, $day) {
      $date = mktime(0, 0, 0, $month, $day, $year);
      $week = date("N", $date);
      return $week == 7 || $week == 6;
   }
   
   /*
    * @author Pwstrick
    * @param array $caculate 通過caculate方法計(jì)算后的數(shù)據(jù)
    * @deprecated 畫表格,設(shè)置table中的tr與td
    */
   function draw($caculate) {
      $tr = array();
      $length = count($caculate);
      $result = array();
      foreach ($caculate as $index => $date) {
         if($index % 7 == 0) {//第一列
            $tr = array($date);
         }elseif($index % 7 == 6 || $index == ($length-1)) {
            array_push($tr, $date);
            array_push($result, $tr);//添加到返回的數(shù)據(jù)中
            $tr = array();//清空數(shù)組列表
         }else {
            array_push($tr, $date);
         }
      }
      return $result;
   }
}
?>


Continuing Learning
||
<?php class Calendar { /* * @deprecated 生成日歷的各個邊界值 * @param string $year * @param string $month * @return array */ function threshold($year, $month) { $firstDay = mktime(0, 0, 0, $month, 1, $year); //mktime() 函數(shù)返回日期的 UNIX 時間戳。 $lastDay = strtotime('+1 month -1 day', $firstDay); //取得天數(shù) $days = date("t", $firstDay); //取得第一天是星期幾 $firstDayOfWeek = date("N", $firstDay); //獲得最后一天是星期幾 $lastDayOfWeek = date('N', $lastDay); //上一個月最后一天 $lastMonthDate = strtotime('-1 day', $firstDay); //strtotime() 函數(shù)將任何英文文本的日期或時間描述解析為 Unix 時間戳 $lastMonthOfLastDay = date('d', $lastMonthDate); //下一個月第一天 $nextMonthDate = strtotime('+1 day', $lastDay); $nextMonthOfFirstDay = strtotime('+1 day', $lastDay); //日歷的第一個日期 if($firstDayOfWeek == 7) { $firstDate = $firstDay; }else { $firstDate = strtotime('-' . $firstDayOfWeek . ' day', $firstDay); } //日歷的最后一個日期 if($lastDayOfWeek == 6) { $lastDate = $lastDay; }elseif($lastDayOfWeek == 7) { $lastDate = strtotime('+6 day', $lastDay); }else { $lastDate = strtotime('+' . (6 - $lastDayOfWeek) . ' day', $lastDay); } return array( 'days' => $days, 'firstDayOfWeek' => $firstDayOfWeek, 'lastDayOfWeek' => $lastDayOfWeek, 'lastMonthOfLastDay' => $lastMonthOfLastDay, 'firstDate' => $firstDate, 'lastDate' => $lastDate, 'year' => $year, 'month' => $month ); } /* * @author Pwstrick * @param array $calendar 通過threshold方法計(jì)算后的數(shù)據(jù) * @deprecated 計(jì)算日歷的天數(shù)與樣式 */ function caculate($calendar) { $days = $calendar['days']; $firstDayOfWeek = $calendar['firstDayOfWeek'];//本月第一天的星期 $lastDayOfWeek = $calendar['lastDayOfWeek'];//本月最后一天的星期 $lastMonthOfLastDay = $calendar['lastMonthOfLastDay'];//上個月的最后一天 $year = $calendar['year']; $month = $calendar['month']; $dates = array(); if($firstDayOfWeek != 7) { $lastDays = array(); $current = $lastMonthOfLastDay;//上個月的最后一天 for ($i = 0; $i < $firstDayOfWeek; $i++) { array_push($lastDays, $current);//添加上一個月的日期天數(shù) $current--; } $lastDays = array_reverse($lastDays);//反序 foreach ($lastDays as $index => $day) { array_push($dates, array('day' => $day, 'tdclass' => ($index ==0 ?'rest':''), 'pclass' => 'outter')); } } //本月日歷信息 for ($i = 1; $i <= $days; $i++) { $isRest = $this->_checkIsRest($year, $month, $i); //判斷是否是休息天 array_push($dates, array('day' => $i, 'tdclass' => ($isRest ?'rest':''), 'pclass' => '')); } //下月日歷信息 if($lastDayOfWeek == 7) {//最后一天是星期日 $length = 6; } elseif($lastDayOfWeek == 6) {//最后一天是星期六 $length = 0; }else { $length = 6 - $lastDayOfWeek; } for ($i = 1; $i <= $length; $i++) { array_push($dates, array('day' => $i, 'tdclass' => ($i==$length ?'rest':''), 'pclass' => 'outter')); } return $dates; } /* * @author Pwstrick * @deprecated 判斷是否是休息天 */ private function _checkIsRest($year, $month, $day) { $date = mktime(0, 0, 0, $month, $day, $year); $week = date("N", $date); return $week == 7 || $week == 6; } /* * @author Pwstrick * @param array $caculate 通過caculate方法計(jì)算后的數(shù)據(jù) * @deprecated 畫表格,設(shè)置table中的tr與td */ function draw($caculate) { $tr = array(); $length = count($caculate); $result = array(); foreach ($caculate as $index => $date) { if($index % 7 == 0) {//第一列 $tr = array($date); }elseif($index % 7 == 6 || $index == ($length-1)) { array_push($tr, $date); array_push($result, $tr);//添加到返回的數(shù)據(jù)中 $tr = array();//清空數(shù)組列表 }else { array_push($tr, $date); } } return $result; } } ?>
submitReset Code