After finding the reason, I searched the internet for some time zone setting methods for PHP:
1, modify the php.ini, found in the php.ini Data.timezone = Remove the front of it, and then set data.timezone = "Asia/shanghai";
2. Use the function ini_set (' Date.timezone ', ' Asia/shanghai ') in the program Code of PHP 5 or above, or date_default_timezone_set (' Asia/shanghai ');
Some common time zone identifiers are described:
asia/shanghai– Shanghai
asia/chongqing– Chongqing
asia/urumqi– Urumqi
asia/hong_kong– Hong Kong
asia/macao– Macau
asia/taipei– Taipei
asia/singapore– Singapore
function to set the time zone method:
Copy CodeThe code is as follows:
Function_exists (Date_default_timezone_set);//In this he always returns 1, this function is to determine if the character is a defined function name
Date_default_timezone_set ("Etc/gmt");//This is Greenwich Mean time, the time to get is the same as the default time zone
Date_default_timezone_set ("etc/gmt+8");//This is 8 hours slower than the Linwei standard time.
Date_default_timezone_set ("etc/gmt-8");//This is 8 hours faster than the Linwei standard time.
Date_default_timezone_set (' PRC '); Set China time zone
?>
The function Ini_set () Sets the time zone:
You can add Ini_set (' Date.timezone ', ' Asia/shanghai ') at the beginning of the file; ' Asia/shanghai ' for Shanghai time zone
To manually modify php.ini settings
Open php found Date.timezone = "PRC" If you have to remove the previous semicolon, no words manually added!
Here are some additional information:
You'll find such a problem when you put the PHP5 on.
$atime =date ("y-m-d h:i:s");
Echo $atime;
?>
Output: 2006-05-16 06:36:06
What time is it now?/mine is 14:36.
Why is this pinching?
The reason is that if you do not set your server local time zone in the program or configuration file
The time taken by PHP is Greenwich Mean time, so there is a discrepancy with your local time.
Greenwich Mean Time and Beijing time is about 8 hours. So how do we avoid time errors?
Let's take a look at the workaround:
In the header, use Date_default_timezone_set () to set my default time zone to GMT
Copy CodeThe code is as follows:
Date_default_timezone_set (' PRC ');
echo Date (' y-m-d h:i:s ');
?>
The time is the same as the current time of the server!
Additional 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).
-------------------------------------------------------------------------------------
or modify the Date.timezone value in php.ini
Date.timezone = PRC
You'll find such a problem when you put the PHP5 on.
$atime =date ("y-m-d h:i:s");
Echo $atime;
?>
Output: 2006-05-16 06:36:06
What time is it now?/mine is 14:36.
Why is this pinching?
The reason is that if you do not set your server local time zone in the program or configuration file
The time taken by PHP is Greenwich Mean time, so there is a discrepancy with your local time.
Greenwich Mean Time and Beijing time is about 8 hours. So how do we avoid time errors?
Let's take a look at the workaround:
In the header, use Date_default_timezone_set () to set my default time zone to GMT
Copy CodeThe code is as follows:
Date_default_timezone_set (' PRC ');
echo Date (' y-m-d h:i:s ');
?>
The time is the same as the current time of the server!
Additional 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).
-------------------------------------------------------------------------------------
or modify the Date.timezone value in php.ini
Date.timezone = PRC
http://www.bkjia.com/PHPjc/325412.html www.bkjia.com true http://www.bkjia.com/PHPjc/325412.html techarticle find the reason, in the online search for some of the PHP time zone setting method: 1, modify php.ini, found in php.ini data.timezone = Remove the front of it, and then set the Data.timezo ...