Use the Mktime () function in PHP to convert a time into a Unix timestamp.
The Mktime () function returns the UNIX timestamp based on the parameters given. The timestamp is a long integer that contains the number of seconds from the Unix era (January 1, 1970) to the given time. Its parameters can be omitted from right to left, any omitted arguments are set to the current value of the cost date and time, and the syntax of the function is as follows:
Mktime (HOUR,MINUTE,SECOND,MONTH,DAY,YEAR,IS_DST)
Parameter description:
Hour is optional. Specified hours.
Minute is optional. Specify minutes.
Second is optional. Specify seconds.
Month is optional. Specifies the number of months to be represented.
Day is optional. Prescribed days.
Year is optional. Prescribed year. On some systems, the legal value is between 1901-2038. However, there is no such limit in PHP 5.
IS_DST is optional. If the time is in daylight saving time (DST), set to 1, otherwise set to 0 and if unknown, set to-1. (since PHP 5.1.0, this parameter has been deprecated.) The new Time zone processing feature should be used instead. )
Note: A valid timestamp typically ranges from Greenwich Mean Time December 13, 1901 20:45:54~2038 January 19 03:14:07 (this range conforms to the minimum and maximum values of 32-bit signed integers), and in Windows systems this range is limited to from January 1, 1970 ~ January 19, 2038.
Localizing Timestamp Instances
This example uses the Mktime () function to get the current time of the system, because the timestamp is returned, and it is formatted with the date () function to output the date and time. The instance code is as follows:
<?phpheader ("Content-type:text/html;charset=utf-8"); Set the encoding echo "The timestamp returned by the Mktime function:". Mktime (). " <br/> "; echo" The current date is: ". Date (" Y-m-d ", Mktime ())." <br/> "; echo" The current time is: ". Date (" H:i:s ", Mktime ());? >
Run results
The above is our simple application of the mktime () function.
A function that gets the current timestamp is specifically provided in PHP. In the next section, we'll show you how to get the current timestamp.