The difference between PHP date and gmdate getting dates _php tips

Source: Internet
Author: User
Tags echo date local time
Date--Format a local time/date

Gmdate-Formats a GMT/UTC date/time and returns Greenwich Standard (GMT).

For example, the time zone we're in is +8, so the server should return the following script:

Current time assumption is 2007-03-14 12:15:27

echo Date (' y-m-d h:i:s ', Time ()); Output: 2007-03-14 12:15:27

echo gmdate (' y-m-d h:i:s ', Time ()); Output: 2007-03-14 04:15:27

But that's just the result of running PHP under Linux+apache, and if you run it under Windows, 2 function returns are: 2007-03-14 04:15:27.

Therefore, we should give a compatibility of the writing, unified use of gmdate, and manually set the current time zone, the wording improved as follows:

echo gmdate (' y-m-d h:i:s ', time () + 3600 * 8);

So no matter under the Linux+apache or Windows have the right results, of course, there is a benefit to write, when the site is facing the world, then the site users just set the time zone, the program automatically based on the time zone set by the user to calculate, When the information in the database is generated by only the current time (), then the release time in China + 8 time zone is: 2007-03-14 12:15:27, then the user in Europe + 2 time zone to see the release time of this information is: 2007-03-14 06:15:27, the time of this information is all correct.
Related Article

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.