- echo Date (' y-m-d h:i:s ', Time ()); Output is: 2013-03-14 12:15:27
- echo gmdate (' y-m-d h:i:s ', Time ()); Output is: 2013-03-14 04:15:27
Copy CodeThe 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:
- echo gmdate (' y-m-d h:i:s ', time () + 3600 * 8);
Copy CodeWith 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. |