Difference between date and gmdate in the date function in php

Source: Internet
Author: User
Difference between date and gmdate in the date function in php

  1. Echo date ('Y-m-d H: I: S', time (); output: 2013-03-14 12:15:27
  2. Echo gmdate ('Y-m-d H: I: S', time (); output: 2013-03-14 04:15:27

The above is the result of running PHP in Linux + Apache.

When running in Windows, both functions are returned: 04:15:27.

Based on compatibility considerations, we need to use gmdate in a unified manner and manually set the current time zone. the improved syntax is as follows:

  1. Echo gmdate ('Y-m-d H: I: S', time () + 3600*8 );

With the above code, both Linux + Apache and Windows get the correct result. another advantage of writing this code is that the website user only needs to set the time zone of the website, the program automatically calculates the time based on the time zone set by the user. the database only saves the time generated by the current time (). the release time displayed in the China + 8 time zone is: 12:15:27, the release time of this information displayed by users in the European + 2 time zone is: 06:15:27, so that all the information time is correct.

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

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.