Difference between date and gmdate in the date function in php
- Echo date ('Y-m-d H: I: S', time (); output: 2013-03-14 12:15:27
- 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:
- 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. |