PHP mktime () function to get local timestamp

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.