In the learning of PHP recently found in PHP format timestamp than Beijing time 8 hours later, the internet search found that the time zone is not correct, the solution is:
1. Permanent modification
Change the Data.timezone = PRC in the php.ini file this is China time. When you restart the Apache service, it takes effect.
2. Temporary modification
Add Ini_set (' Date.timezone ', ' Asia/shanghai ') before using the formatted input time;
or Data_default_timezone_set (' PRC '); the//date_default_timezone_set () function sets the default time zone for all date/time functions in the script.
Look at the problems the other partners are having.
One of the remaining problems is that echo date ("Y-m-d h:i:s", Time ()) always comes back with the actual time, and today finally found the reason and solution on the Internet, sharing the following:
Add a point, follow the method of the following prompts to modify PHP.ini find Date.timezone This line, is not there is no way, of course not, haha no words on their own add well, their hands and clothing. Add such a sentence Date.timezone = "PRC", the problem is settled, happy
Starting with php5.1.0, PHP.ini added the Date.timezone option, which is closed by default
That is to show the time (no matter what PHP command) is Greenwich Standard Time, and our time (Beijing time) is bad for just 8 hours, there are the following 3 methods can restore normal time.
1, the easiest way is not to use the php5.1 version
2, if you must use, and can not modify the php.ini, you need to initialize the time of the statement above plus Date_default_timezone_set (XXX);
3, once and for all, only can modify php.ini. Open php.ini Find Date.timezone remove the preceding semicolon
= Add xxx back, 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)
Taiwan available: Asia/macao, Asia/hong_kong, Asia/taipei (Macau, Hong Kong, Taipei)
and Singapore: Asia/singapore
The foreigner seems to have leaked Beijing
Other available values are: etc/gmt-8, Singapore, Hongkong, PRC
What is PRC? PRC is the People's Republic of China Ah-_-
———————————————————————————————————————
Workaround: Use Date_default_timezone_set () in the header to set my default time zone to be the Beijing Times date_default_timezone_set (' PRC ');
echo Date (' y-m-d h:i:s '); Time is the same as the server current time!! The attached date_default_timezone_set use is as follows
——————————–
Date_default_timezone_set
(PHP 5 >= 5.1.0rc1)
date_default_timezone_set-Sets the default time zone description for all date-time functions in a script
BOOL Date_default_timezone_set (String timezone_identifier)
Date_default_timezone_set () Sets the default time zone for all date-time functions.
Note: Since PHP 5.1.0 (This version of the date time function has been rewritten), if the time zone does not rule every call to a datetime function generates a E_notice level error message.
The above mentioned is the entire content of this article, I hope you can enjoy.