Mktime and gmmktime

Source: Internet
Author: User
Tags time zones
Int Mktime([Int $ Hour[, Int $ Minute[, Int $ Second[, Int $ Month[, Int $ Day[, Int $ Year[, Int $ Is_dst])

 

Returns the Unix timestamp Based on the given parameters. The timestamp is a long integer that contains the number of seconds from the Unix epoch (January 1 1970 00:00:00 GMT) to the given time.

The parameter can be omitted from the right to the left. Any omitted parameter is set to the current value of the local date and time.

 

 

Int Gmmktime([Int $ Hour[, Int $ Minute[, Int $ Second[, Int $ Month[, Int $ Day[, Int $ Year[, Int $ Is_dst])

Similar to mktime (), only the timestamp when the return value is Greenwich Mean Time.

The parameter always represents the GMT date, soIs_dstThe result is not affected.

Like mktime (), the parameters can be left empty from right to left, and the empty parameters are set to the corresponding current GMT value.

 

The introduction to the PHP manual is vague. Two examples are given below:

First, set date. timezone in php. ini to date. timezone = PRC.

<? Php
$ Ltime = mktime ();
$ Gtime = gmmktime ();
Echo "$ ltime <br/> $ gtime <br/> ";
?>

The output result is as follows:

 

1315311558
1315311558

 

The returned results of the two functions are the same. According to my understanding, a timestamp that returns the local time and a timestamp that returns the GMT time must be 8 hours different.

 

Let's look at another example:

<? Php
$ Ltime = mktime );
$ Gtime = gmmktime );
Echo "$ ltime <br/> $ gtime <br/> ";
?>

The output result is as follows: 631123200
631152000

(631152000-631123200)/3600 = 8, which is 8 hours different. That's right.

 

Analysis of the above two examples:

(1) In the first example, although gmmktime returns the timestamp of the current GMT time, however, the default parameters include the hour, minute, second, month, day, and year of the current GMT time, while the mktime parameter is used by default.

Time, minute, second, month, day, and year. In this way, after time is converted to GMT in mktime, it will be the same as the value of gmmktime, so their return values are the same.

(2) In the second example, the values of the mktime and gmmktime parameters are fixed and dead 00:00:00, therefore, in mktime, 00:00:00 is converted to GMT and the timestamp is calculated. Beijing time is eight time zones larger than GMT time, therefore, the mktime calculation method is to subtract 8 hours from 00:00:00 on January 1, which is why the returned value of gmmktime is eight hours greater than the return value of mktime.

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.