PHP development...LOGIN

PHP development to create a simple calendar to generate each boundary value of the calendar

113.png

Custom function threshold method to generate each boundary value of the calendar

1) Calculate the total number of days in this month

2) Calculate the first day of this month day and last day, each is a day of the week

3) Calculate the first date and last date in the calendar

<?php
function threshold($year, $month) {
    $firstDay = mktime(0, 0, 0, $month, 1, $year);
    $lastDay = strtotime('+1 month -1 day', $firstDay);
    //取得天数  
    $days = date("t", $firstDay);
    //取得第一天是星期几
    $firstDayOfWeek = date("N", $firstDay);
    //获得最后一天是星期几
    $lastDayOfWeek = date('N', $lastDay);
    //上一个月最后一天
    $lastMonthDate = strtotime('-1 day', $firstDay);
    $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
    );
}
?>

Note:

mktime() function returns the date UNIX timestamp.

The strtotime() function parses any English text date or time description into a Unix timestamp (number of seconds since January 1 1970 00:00:00 GMT).

Next Section
<?php function threshold($year, $month) { $firstDay = mktime(0, 0, 0, $month, 1, $year); $lastDay = strtotime('+1 month -1 day', $firstDay); //取得天数 $days = date("t", $firstDay); //取得第一天是星期几 $firstDayOfWeek = date("N", $firstDay); //获得最后一天是星期几 $lastDayOfWeek = date('N', $lastDay); //上一个月最后一天 $lastMonthDate = strtotime('-1 day', $firstDay); $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 ); } ?>
submitReset Code
ChapterCourseware