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

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).
new file
<?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
);
}
?>
Preview
Clear
- Course Recommendations
- Courseware download
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~
Students who have watched this course are also learning
Let's briefly talk about starting a business in PHP
Quick introduction to web front-end development
Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
Login verification and classic message board
Computer network knowledge collection
Quick Start Node.JS Full Version
The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
















