In Windows, in the default PHP configuration, the time value returned by the date function is always 8 hours different from the local time, that is, the Greenwich mean time is displayed. The solution is to correctly set the time zone of PHP. The time zone of PHP is specified by a specific string. See the list of time zones supported by PHP. The most convenient way is to find a line of date. timezone in the php. ini file. by default, this line is commented out and can be enabled by deleting the semicolon. For mainland China, you can set itEtc/GMT-8(OrAsia/Sanghai,Asia/Chongqing,Asia/Urumqi,PRC). If you cannot modify php. ini for some reason, use date_default_timezone_set () in the PHP program. For example, you can run date_default_timezone_set('Etc/GMT-8'); I personally think it is better to use the date_default_timezone_set function. First, it is highly Universal. Second, if your website is for global users, this method allows every user to set his/her time zone. It should be noted that The Etc/GMT method is used. Mainland China adopts the UTC + 8 zone time, generally are recorded as + 8, but PHP comes a big inverse, to write Etc/GMT-8; on the contrary, if your time zone is in the West 2 region, you need to write Etc/GMT + 2 in PHP. This is different from common sense.
The above is the solution for php's 8-hour difference in date time. For more information, see PHP Chinese website (www.php1.cn )!
|