PHP mktime
The PHP mktime function is used to obtain the Unix timestamp. You can set the hour, minute, second, month, day, and year to be formatted by yourself, and let mktime help you convert it to Unix timestamp, which is represented by Unix timestamp It means that from 00:00:00 GMT on January 1, 1970, to the set time difference in seconds, it is very useful when the system needs time calculation, because it is presented in seconds, so it can be added and subtracted directly. It is also easy to convert the number of seconds back to other time formats.
Basic syntax of PHP mktime function
PHP mktime function parameter list
| int $hour | Time, you can directly give a number or use date("H") to let PHP read the time of the server at that time. |
| int $minute | Minutes, you can directly give numbers or use date("i") to let PHP read the current server minutes. |
| int $second | For seconds, you can directly give numbers or use date("s") to let PHP read the seconds of the server at that time. |
| int $month | Month, you can directly give a number or use date("n") to let PHP read the month of the server at that time. |
| int $day | For the day, you can directly give a number or use date("j") to let PHP read the day of the server at that time. |
| int $year | Year, you can directly give a number or use date("Y") to let PHP read the year of the server at that time. |
| int $is_dst | It can be omitted, this parameter has been discarded in versions after PHP 5.1.0. |
When the program is not used to calculate a fixed time difference, but to calculate the time difference at the time, it is very convenient to use the PHP date function .
PHP mktime example
echo mktime(date("H"),date("i"),date("s"),date("n"),date("j"),date("Y")).' <br>';
echo mktime();
?>
PHP mktime automatic adjustment
echo date("MdY", mktime(0, 0, 0, 13, 33, 1988)).'<br>'; // Automatically adjust to Feb-02-1989
echo date("MdY", mktime(0, 0, 0, 8, 1, 2013)).'<br>'; // Automatically adjust to Aug-01-2013
echo date("MdY", mktime(0, 0, 0, 0, 1, 2013)).'<br>'; // Automatically adjust to Dec-01-2012
echo date("MdY", mktime(0, 0, 0, 1, 1, 01)).'<br> '; // Automatically adjust Jan-01-2001
?>
Post a Comment
0 Comments