The difference between date and gmdate functions in PHP

Source: Internet
Author: User
There are 2 functions for formatting time in PHP: Date () and Gmdate (), as described in the official documentation:
Date--Formatting a local time/date
Gmdate--Formats a GMT/UTC date/time and returns Greenwich Mean Time (GMT).
For example, we are currently in a time zone of +8, so the time that the server runs the following script should return:
The current time is assumed to be 2009-01-04 12:15:27
echo Date (' y-m-d h:i:s ', Time ()); Output is: 2009-01-04 12:15:27
echo gmdate (' y-m-d h:i:s ', Time ()); Output is: 2009-01-04 04:15:27
But this is only the result of running PHP under Linux+apache, if run under Windows, then 2 functions returned are: 2009-01-04 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: 2009-01-04 12:15:27, then in Europe + 2 time zone users see this information published: 2009-01-04 06:15:27, so the time of the message is all right. Reprint please indicate source: PHP in the difference between the date and gmdate function

The above is the PHP date and gmdate function of the difference between the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.