PHP date/time function
Definitions and usage
The Mktime () function returns a Unix timestamp for a date.
The parameter always represents the GMT date, so IS_DST has no effect on the result.
The parameters can be left-to-right, and the empty arguments will be set to the appropriate current GMT value.
Grammar
Mktime (HOUR,MINUTE,SECOND,MONTH,DAY,YEAR,IS_DST) parameter description
Hour optional. Set hours.
Minute optional. Specify minutes.
Second Optional. Specified seconds.
Month optional. A month that is specified in numbers.
Day is optional. Stipulated day.
Year is optional. Set year. On some systems, the legal value is between 1901-2038. However, there is no such limit in PHP 5.
Is_dst Optional. If time is in daylight saving time (DST), set to 1, otherwise set to 0, if unknown, set to-1.
Since 5.1.0, IS_DST parameters have been discarded. Therefore, you should use the new time zone processing attributes.
Tips and comments
Note: Before PHP 5.1, false is returned if the function's arguments are illegal.
Example
The Mktime () function is useful for date operations and validation. It can automatically correct the input that crosses the line:
<?php Tutorial
Echo (Date ("M-d-y", Mktime (0,0,0,12,36,2001));
Echo (Date ("M-d-y", Mktime (0,0,0,14,1,2001));
Echo (Date ("M-d-y", Mktime (0,0,0,1,1,2001));
Echo (Date ("M-d-y", Mktime (0,0,0,1,1,99));
?> output:
jan-05-2002
feb-01-2002
jan-01-2001
jan-01-1999
Example #1 mktime () basic Example
<?php
Set The default timezone to use. Available as of PHP 5.1
Date_default_timezone_set (' UTC ');
Prints:july 1, on a Saturday
echo "July 1, is on a". Date ("L", mktime (0, 0, 0, 7, 1, 2000));
Prints something like:2006-04-05t01:02:03+00:00
echo Date (' C ', Mktime (1, 2, 3, 4, 5, 2006));
?>
Mktime () is useful for date calculations and validation because it automatically calculates the range input for the correct value. For example, each of the following lines will produce a string "jan-01-1998"
。
<?php
echo Date ("M-d-y", mktime (0, 0, 0, 12, 32, 1997));
echo Date ("M-d-y", mktime (0, 0, 0, 13, 1, 1997));
echo Date ("M-d-y", mktime (0, 0, 0, 1, 1, 1998));
echo Date ("M-d-y", mktime (0, 0, 0, 1, 1, 98));
?>
<?php
$lastday = mktime (0, 0, 0, 3, 0, N);
Echo strftime ("Last day in Feb:%d", $lastday); $lastday = mktime (0, 0, 0, 4,-31, 2000);
Echo strftime ("Last day in Feb:%d", $lastday);
?