php > About PHP time zone timing error Problem date current time difference (reprint)
About PHP TimeZone time error problem date current time difference local local Date_default_timezone_set
One legacy of the previous problem is that echo date ("Y-m-d h:i:s", Time ()) is always back with the actual time, and today finally found the reason and solution on the Internet, share the following:
I add that I follow the instructions below to modify php.ini can not find Date.timezone this line, is not the way it is, of course, no, haha no words on their own add, self-clothed. I added such a sentence Date.timezone = "PRC", the problem is done, happy.
Starting with php5.1.0, PHP.ini added the Date.timezone option, which is turned off by default
That is, the time displayed (whatever PHP command is used) is Greenwich Mean Time
And our Time (Beijing time) The difference is exactly 8 hours, there are the following 3 methods can restore normal time.
1, the simplest way is not to use the version of php5.1 above
2, if must be used, and can not modify the php.ini, it is necessary in relation to the initialization of the time of the statement
Add Date_default_timezone_set (XXX) above;
CP does not have this problem
3, once and for all, can only modify php.ini. Open php.ini Find Date.timezone remove the preceding semicolon
= Add xxx After, restart HTTP service (such as Apache2 or IIS, etc.)
For XXX, the values available in mainland China are: asia/chongqing, Asia/shanghai, Asia/urumqi (Chongqing, Shanghai, Urumqi, respectively)
Taiwan available: Asia/macao, Asia/hong_kong, Asia/taipei (Macau, Hong Kong, Taipei, respectively)
and Singapore: Asia/singapore
The foreigner seems to have missed Beijing's tune.
Other available values are: Etc/gmt-8, Singapore, Hongkong, PRC
What is PRC? PRC is the People's Republic of China Ah-_-
---------------------------------------------
How to resolve:
In the header, use Date_default_timezone_set () to set my default time zone to GMT
Date_default_timezone_set (' PRC ');
echo Date (' y-m-d h:i:s ');
Time is the same as the current time of the server!! Congratulations on the
Attached date_default_timezone_set usage is as follows
--------------------------------
Date_default_timezone_set
(PHP 5 >= 5.1.0rc1)
Date_default_timezone_set--Set the default time zone for all datetime functions in a script
Description
BOOL Date_default_timezone_set (String timezone_identifier)
Date_default_timezone_set () Sets the default time zone for all datetime functions.
??? Note: Since PHP 5.1.0 (This version of the date time function is rewritten), each call to a DateTime function will produce an E_notice level error message if the time zone is not in law.
Parameters
Timezone_identifier
??? Time zone identifiers, such as UTC or Europe/lisbon
return value
This function always returns TRUE (even if the timezone_identifier argument is not valid).
------------------------------------------------------
Enclose the time zone identifier:
Cet
Cst6cdt
The
Egypt
Eire
Est
Est5edt
Etc/gmt
Etc/gmt+0
Etc/gmt+1
Etc/gmt+10
Etc/gmt+11
Etc/gmt+12
Etc/gmt+2
Etc/gmt+3
Etc/gmt+4
Etc/gmt+5
Etc/gmt+6
Etc/gmt+7
Etc/gmt+8
Etc/gmt+9
etc/gmt-0
Etc/gmt-1
Etc/gmt-10
Etc/gmt-11
Etc/gmt-12
Etc/gmt-13
Etc/gmt-14
Etc/gmt-2
Etc/gmt-3
Etc/gmt-4
Etc/gmt-5
Etc/gmt-6
Etc/gmt-7
Etc/gmt-8
Etc/gmt-9
Etc/gmt0
Etc/greenwich
Etc/uct
Etc/universal
Etc/utc
Etc/zulu
Factory
GB
Gb-eire
Gmt
Gmt+0
GMT-0
GMT0
Greenwich
Hongkong
HST
Iceland
Iran
Israel
Jamaica
Japan
Kwajalein
Libya
MET
Mst
Mst7mdt
Navajo
NZ
Nz-chat
Poland
Portugal
PRC
Pst8pdt
ROC
ROK
Singapore
Turkey
UCT
Universal
Utc
W-su
WET