Php. date is added to ini. the timezone option is disabled by default, that is, the displayed time (no matter what php command is used) is the Greenwich mean time, and our time (Beijing time) the difference is exactly 8 hours. in the following three ways, we can restore the normal time. 1. the simplest method is not to use php5.1 or a later version; 2. if you want to use version 5.1 or later without modifying php. ini, add date_default_timezone_set (XXX) to the statement about time initialization, or use date ('Y-m-d G: I: t ', strtotime ('+ 8HOUR') to obtain the date and time; 3. once and for all, only php. ini can be modified. Open php. ini, remove the semicolon before date. timezone, add XXX to =, and restart the http service (such as apache2 or iis. For XXX, the available values in mainland China are: Asia/Chongqing, Asia/Shanghai, Asia/Urumqi (Chongqing, Shanghai, and Urumqi in sequence), and Hong Kong and Taiwan regions are available: Asia/Maca *, asia/Hong_Kong, Asia/Taipei (in the order of Macao, Hong Kong, and Taipei), and Singapore: Asia/Singapore. there is no Beijing in the preceding figure. However, the other available values are as follows: etc/GMT-8, Singapore, Hongkong, PRC. What is PRC? PRC is the People's Republic of China! (This is Beijing time) above are php official documentation files sorted out the GMT-8 below the area, may have omissions, if you need to view the official document here better :)
When date ("H: I: s") is used in PHP5 today, it is found that the time retrieved by the parameter "H" is different from the time in the window. I checked the information and found that php. ini of PHP5 is set: [Date] ; Defines the default timezone used by the date functions ; Date. timezone = In this way, the default time is GMT. Generally, we use Beijing time and can set it to: date. timezone = PRC or date. timezone = Asia/Shanghai. That is: [Date] ; Defines the default timezone used by the date functions Date. timezone = Asia/Shanghai Do not set it to "Asia/Beijing". foreigners may be interested in Shanghai. If you do not have permission to change php. ini, you can use the date_default_timezone_set ('prc') function or date_default_timezone_set ('Asia/Shanghai '); This function is used to set the default time zone of all datetime functions. As described in the manual: "Since PHP 5.1.0 (the date and time functions of this version have been rewritten ), if the time zone is invalid, every call to the DATETIME function will generate an E_NOTICE-level error message ". But "this function always returns TRUE (even if Next, let's take a look at the function: string The return values of this function follow the following sequence: 1: Use the TZ environment variable (if not empty ). 3: date. timezone configuration option (if set ). 4: I guess (if supported by the operating system ). 5: If none of the above options is successful, return Learn more about UTC: Coordinated Universal Time (UTC ): A compromise called Coordinated Universal Time was launched in 1972. To ensure that the difference between the Coordinated Universal Time and the universal time (UT1) is no more than 0.9 seconds, a positive or negative leap second is added in the coordinated universal time when necessary. Therefore, there will be several integer-second differences between the Coordinated Universal Time and the International Atomic Time (TAI. The Paris-based IERS is responsible for deciding when to join a leap second.
UTC = Coordinated Universal Time. the Chinese name is Coordinated Universal Time. GMT = Greenwich Mean Time. Chinese name is Greenwich Mean (Ping) (here "w" is not pronounced, and "Green" should be read as "Gren ") UTC = GMT +/-0.9 s Therefore, "leap second" is required between UTC to control the difference between the two. |
The time zone of php5.1x is incorrect for eight hours! Favorites Since php5.10, the time zone settings have been added to php. the time displayed in php is Greenwich Mean Time, which causes eight hours of downtime for Chinese users! Modify the date. timezone parameter in php. ini: [Date] ; Defines the default timezone used by the date functions ; Date. timezone = It is disabled by default. you only need to remove the comment and change it [Date] ; Defines the default timezone used by the date functions Date. timezone = PRC PRC is the People's Republic of China "! For other options, refer to the php Manual. However, the above Asia region missed our capital, Beijing. I don't know if foreigners intentionally did it! If you do not have the permission to modify php. ini, you only need to call date_default_timezone_set ('prc') when calling the time and date function! You can also call date_default_timezone_get () to view the current time zone settings! ? XXX, big ?? The available values are: Asia/Chongqing, Asia/Shanghai, Asia/Urumqi (sequential? Heavy ?, Shanghai ,?? Wood ?) Hong Kong and Taiwan? Available: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (sequential? Australia ?, Hong Kong, Taipei) Platform? What is the region ?? : Date. timezone = "Asia // Taipei" ? Singapore: Asia/Singapore This article from The CSDN blog, reproduced please indicate the source: http://blog.csdn.net/keenx/archive/2006/03/21/631432.aspx From dedecms: php5 time zone settings If (PHP_VERSION> '5. 1 '){ $ Time51 = 'etc/GMT'. ($ 1__cli_time> 0? '-': '+'). Abs ($ pai_cli_time ); Function_exists ('date _ default_timezone_set ')? @ Date_default_timezone_set ($ time51 ):''; }
If php version is later than 5.1, run $ Pai_cli_time =-8; that is, 8 hours less! Format and set it with data_default_timezone_set ("Etc/GMT + 8 !! Beijing time zone should be Etc/GMT + 8
Generally, the time zone is set to + 8 hours! GMT) $ Date = gmdate ("Y-m-d H: I: s", time () + 8*3600) You only need to add 8 hours! Just write a function or something. |