PHP date and Gmdate Get the date difference you know what?

Source: Internet
Author: User
Tags echo date
Time in PHP has 2 formatting functions: Date () and Gmdate ()

The date () function formats the local date and time and returns the formatted date string. Gmdate--Formats a GMT/UTC date/time and returns Greenwich Mean Time (GMT).

The Gmdate () function formats the GMT/UTC date and time and returns the formatted date string.

For example, we are now in the time zone is +8, then the server run the following script to return the time should be this:

The current time is assumed to be 2017-07-11 12:15:27

echo Date (' y-m-d h:i:s ', Time ()); Output is: 2017-07-11 12:15:27

echo gmdate (' y-m-d h:i:s ', Time ()); Output is: 2017-07-11 04:15:27

But this is only the result of running PHP under Linux+apache, if run under Windows, then 2 functions returned are: 2017-07-11 04:15:27.

Therefore, we should give a compatibility of the wording, unified use of gmdate, and manually set the current time zone, the following improvements:

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

So no matter under the Linux+apache or windows are getting the correct results, of course, there is a benefit to write, when the site is facing the world, then the site users as long as the settings in the time zone, the program automatically based on the time zone set by the user to calculate, The publication time of the information in the database is only the time that is generated by the current date (), then the published time in China + 8 time zone is: 2017-07-11 12:15:27, then in Europe + 2 time zone users see this information published: 2017-07-11 06:15:27, the time for this information is all right.

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.