The difference between date function dates in PHP and gmdate on Get date

Source: Internet
Author: User
Tags echo date
  1. echo Date (' y-m-d h:i:s ', Time ()); Output is: 2013-03-14 12:15:27
  2. echo gmdate (' y-m-d h:i:s ', Time ()); Output is: 2013-03-14 04:15:27
Copy Code

The above is the result of running PHP under Linux+apache.

Running under Windows, the 2 functions returned are: 2013-03-14 04:15:27.

Based on compatibility considerations, we need to unify the gmdate and set the current time zone manually, with the following improved wording:

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

With the above code, whether under the Linux+apache or under windows are getting the correct results, this is another advantage of writing: As long as the site user settings in the time zone, the program automatically according to the time zone set by the user to calculate the times, the information in the database is published only the current time ( The generated time, then in China + 8 time zone to see the release time is: 2013-03-14 12:15:27, then in Europe + 2 time zone users see this information published time is: 2013-03-14 06:15:27, so that the time of the information is all correct.

I didn't care too much about these two time-format functions, today we learned the difference between date and gmdate in processing dates and finally know how to apply them.

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