Use the mktime() function in PHP to convert a time into a UNIX timestamp.
The mktime() function returns a UNIX timestamp based on the parameters given. A timestamp is a long integer containing the number of seconds since the UNIX epoch (January 1, 1970) to a given time. Its parameters can be omitted from right to left. Any omitted parameters will be set to the current value of the local date and time. Thesyntax formatof this function is as follows:
mktime(hour,minute,second,month,day,year,is_dst)
Parameter description :
hour Optional. Specified hours.
minute Optional. Specified minutes.
second Optional. Specifies seconds.
month Optional. Specifies the numeric month.
day Optional. Specify days.
year Optional. Specified year. On some systems, legal values are between 1901 - 2038. However, this limitation no longer exists in PHP 5.
is_dst Optional. Set to 1 if the time is during Daylight Saving Time (DST), 0 otherwise, or -1 if unknown. (As of PHP 5.1.0, this parameter has been deprecated. The new time zone handling features should be used instead.)
Note: The typical range of valid timestamps is 1901 GMT 12 January 13, 20:45:54~January 19, 2038, 03:14:07 (this range conforms to the minimum and maximum values of 32-bit signed integers). In Windows systems, this range is limited to January 1970 1st ~ January 19th, 2038.
Localized timestamp example
This example uses the mktime() function to obtain the current time of the system. Since the timestamp is returned, the date() function must be used. Format it to output the date and time. The example code is as follows:
"; echo "当前的日期为:".date("Y-m-d",mktime())."
"; echo "当前的时间为:".date("H:i:s",mktime()); ?>
The running result is as shown in the figure:
The above is our simple application of the mktime() function.
In PHP, a function is specially provided to obtain the current timestamp. In the next section, we will explain how to get the current timestamp.
The above is the detailed content of PHP mktime() function gets local timestamp. For more information, please follow other related articles on the PHP Chinese website!