The mktime () function returns the Unix timestamp of a date. The parameter always represents the GMT date, so is_dst has no effect on the result. The parameters can be left empty from right to left...
Show the starting and ending points of this month, last month, today, and this year
The mktime () function returns the Unix timestamp of a date.
The parameter always represents the GMT date, so is_dst has no effect on the result.
The parameters can be left empty from right to left. the blank parameters are set to the corresponding current GMT value.
PHP Date () function
The PHP Date () function can format the timestamp as a Date and time with better readability.
Syntax
Date (format, timestamp) parameter description
Format is required. The format of the specified timestamp.
Optional. The specified timestamp. The default value is the current date and time.
The mktime and date functions are briefly described above. let's take a look at the date calculation using their instances today, last month, and next month.
$t = time(); $t1 = mktime(0,0,0,date("m",$t),date("d",$t),date("Y",$t)); $t2 = mktime(0,0,0,date("m",$t),1,date("Y",$t)); $t3 = mktime(0,0,0,date("m",$t)-1,1,date("Y",$t)); $t4 = mktime(0,0,0,1,1,date("Y",$t)); $e1 = mktime(23,59,59,date("m",$t),date("d",$t),date("Y",$t)); $e2 = mktime(23,59,59,date("m",$t),date("t"),date("Y",$t)); $e3 = mktime(23,59,59,date("m",$t)-1,date("t",$t3),date("Y",$t)); $e4 = mktime(23,59,59,12,31,date("Y",$t));
Refer to the mktime () function
Parameters |
Description |
Hour |
Optional. The specified hour. |
Minute |
Optional. Minutes. |
Second |
Optional. Specified seconds. |
Month |
Optional. Indicates the month in number. |
Day |
Optional. Specified day. |
Year |
Optional. Specified year. In some systems, the valid value ranges from 1901 to 2038. However, this restriction does not exist in PHP 5. |
Is_dst |
Optional. If the time is in the daylight saving time (DST) period, it is set to 1; otherwise, it is set to 0. if it is unknown, it is set to-1. The is_dst parameter has been deprecated since 5.1.0. Therefore, the new time zone processing feature should be used. |
// Test echo date ("current Y-m-d H: I: s", $ t). "$ t
"; Echo date (" Today's start point Y-m-d H: I: s ", $ t1)." $ t1
"; Echo date (" starting from Y-m-d H: I: s ", $ t2)." $ t2
"; Echo date (" Starting from last month Y-m-d H: I: s ", $ t3)." $ t3
"; Echo date (" this year's start point Y-m-d H: I: s ", $ t4)." $ t4
"; // Test echo date (" End today Y-m-d H: I: s ", $ e1)." $ e1
"; Echo date (" end of this month Y-m-d H: I: s ", $ e2)." $ e2
"; Echo date (" last month end Y-m-d H: I: s ", $ e3)." $ e3
"; Echo date (" end of this year Y-m-d H: I: s ", $ e4)." $ e4
"; Result: currently 15:42:55 1306222975 today's start point 00:00:00 1306166400 this month's start point 00:00:00 1304179200 last month's start point 00:00:00 1301587200 this year's start point 00:00:00 1293811200 today's end point 23:59:59 1306252799 last month's end point 23:59:59 1304179199 end of this year 23:59:59 1325347199
Let's take a look at the date function.
Parameters |
Description |
Format |
Required. The format of the specified timestamp. |
Timestamp |
Optional. The specified timestamp. The default value is the current date and time. |
PHP date-format date
The first parameter of the date () function specifies how to format the date/time. It uses letters to indicate the date and time formats. Some available letters are listed here:
Day in d-month (01-31)
M-current month, in numbers (01-12)
Y-current year (four digits)
You can find all the letters that can be used in the format parameters in our PHP Date reference manual.
Tutorial link:
Reprint at will ~ However, please keep the tutorial address★