Summary of the time zone setting method in PHP
- 2020-05-17 05:00:10
- OfStack
After finding the reason, I searched the Internet and found 1 time zone setting method about PHP:
1. Modify php.ini, find data.timezone = remove the one before it in php.ini; data. timezone = "Asia/Shanghai"; Can.
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 ');
1 some common time zone identifiers:
Shanghai Asia/Shanghai �
Asia/Chongqing � in chongqing
Urumqi, xinjiang. Asia/Urumqi
Asia/Hong_Kong � Hong Kong
Asia/Macao � macau
Asia/Taipei � in Taipei
Asia/Singapore, Singapore
Function time zone setting method:
The function ini_set() sets the time zone:
You can add ini_set(' date.timezone ','Asia/Shanghai') to the beginning of the file; / / 'Asia/Shanghai' is the time zone of Shanghai
Manually modify the php.ini Settings
Open php and find date. timezone = "PRC".
The following is a supplement:
You'll find this problem when you install PHP5
$atime=date("Y-m-d H:i:s");
echo $atime;
? >
Output: the 2006-05-16 06:36:06
What time is it? / mine is 14:36
Why is this pinching?
The reason is if you do not set your server's local time zone in the application or configuration file
The time taken by PHP is Greenwich mean time, so it is different from your local time
Greenwich mean time and Beijing time are about 8 hours apart so how do we avoid that?
Let's take a look at the solution:
Use date_default_timezone_set () in the header to set my default time zone to Beijing time
Time and server current time 1 like!
The usage of date_default_timezone_set is attached as follows:
------------------------------------------------------------------------------------
date_default_timezone_set
(PHP 5 > = 5.1.0RC1)
date_default_timezone_set -- sets the default time zone for all date and time functions in a script
instructions
bool date_default_timezone_set ( string timezone_identifier )
date_default_timezone_set() sets the default time zone for all date and time functions.
Note: since PHP 5.1.0 (this version of the datetime function has been rewritten), each call to the datetime function will generate an E_NOTICE level error message if the time zone is not compliant.
parameter
timezone_identifier
Time zone identifiers, such as UTC or Europe/Lisbon
The return value
This function always returns TRUE (even if the timezone_identifier parameter is not valid).
-------------------------------------------------------------------------------------
Or modify the date.timezone value in php.ini
date.timezone = PRC
You will find this problem when you install PHP5
$atime=date("Y-m-d H:i:s");
echo $atime;
? >
Output: the 2006-05-16 06:36:06
What time is it? / mine is 14:36
Why is this pinching?
The reason is if you do not set your server's local time zone in the application or configuration file
The time taken by PHP is Greenwich mean time, so it will differ from your local time
Greenwich mean time and Beijing time are about 8 hours apart so how do we avoid that?
Let's take a look at the solution:
Use date_default_timezone_set () in the header to set my default time zone to Beijing time
Time and server current time 1 like!
The usage of date_default_timezone_set is also attached as follows:
------------------------------------------------------------------------------------
date_default_timezone_set
(PHP 5 > = 5.1.0RC1)
date_default_timezone_set -- sets the default time zone for all date and time functions in a script
instructions
bool date_default_timezone_set ( string timezone_identifier )
date_default_timezone_set() sets the default time zone for all date and time functions.
Note: since PHP 5.1.0 (this version of the date-time function has been rewritten), each call to the date-time function will generate an E_NOTICE level error message if the time zone is inconsistent.
parameter
timezone_identifier
Time zone identifiers, such as UTC or Europe/Lisbon
The return value
This function always returns TRUE (even if the timezone_identifier parameter is not valid).
-------------------------------------------------------------------------------------
Or modify the value of date.timezone in php.ini
date.timezone = PRC
1. Modify php.ini, find data.timezone = remove the one before it in php.ini; data. timezone = "Asia/Shanghai"; Can.
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 ');
1 some common time zone identifiers:
Shanghai Asia/Shanghai �
Asia/Chongqing � in chongqing
Urumqi, xinjiang. Asia/Urumqi
Asia/Hong_Kong � Hong Kong
Asia/Macao � macau
Asia/Taipei � in Taipei
Asia/Singapore, Singapore
Function time zone setting method:
<?php
function_exists(date_default_timezone_set);// Here he always returns 1, This function is to determine whether the character in here is or is not 1 The names of defined functions
date_default_timezone_set("Etc/GMT");// This is Greenwich mean time , The resulting time and the default time zone are 1 The sample of
date_default_timezone_set("Etc/GMT+8");// It's slower than lindwich standard time 8 hours
date_default_timezone_set("Etc/GMT-8");// It's faster than lindwich standard time 8 hours
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') to the beginning of the file; / / 'Asia/Shanghai' is the time zone of Shanghai
Manually modify the php.ini Settings
Open php and find date. timezone = "PRC".
The following is a supplement:
You'll find this problem when you install PHP5
$atime=date("Y-m-d H:i:s");
echo $atime;
? >
Output: the 2006-05-16 06:36:06
What time is it? / mine is 14:36
Why is this pinching?
The reason is if you do not set your server's local time zone in the application or configuration file
The time taken by PHP is Greenwich mean time, so it is different from your local time
Greenwich mean time and Beijing time are about 8 hours apart so how do we avoid that?
Let's take a look at the solution:
Use date_default_timezone_set () in the header to set my default time zone to Beijing time
<?
date_default_timezone_set('PRC');
echo date('Y-m-d H:i:s');
?>
Time and server current time 1 like!
The usage of date_default_timezone_set is attached as follows:
------------------------------------------------------------------------------------
date_default_timezone_set
(PHP 5 > = 5.1.0RC1)
date_default_timezone_set -- sets the default time zone for all date and time functions in a script
instructions
bool date_default_timezone_set ( string timezone_identifier )
date_default_timezone_set() sets the default time zone for all date and time functions.
Note: since PHP 5.1.0 (this version of the datetime function has been rewritten), each call to the datetime function will generate an E_NOTICE level error message if the time zone is not compliant.
parameter
timezone_identifier
Time zone identifiers, such as UTC or Europe/Lisbon
The return value
This function always returns TRUE (even if the timezone_identifier parameter is not valid).
-------------------------------------------------------------------------------------
Or modify the date.timezone value in php.ini
date.timezone = PRC
You will find this problem when you install PHP5
$atime=date("Y-m-d H:i:s");
echo $atime;
? >
Output: the 2006-05-16 06:36:06
What time is it? / mine is 14:36
Why is this pinching?
The reason is if you do not set your server's local time zone in the application or configuration file
The time taken by PHP is Greenwich mean time, so it will differ from your local time
Greenwich mean time and Beijing time are about 8 hours apart so how do we avoid that?
Let's take a look at the solution:
Use date_default_timezone_set () in the header to set my default time zone to Beijing time
<?
date_default_timezone_set('PRC');
echo date('Y-m-d H:i:s');
?>
Time and server current time 1 like!
The usage of date_default_timezone_set is also attached as follows:
------------------------------------------------------------------------------------
date_default_timezone_set
(PHP 5 > = 5.1.0RC1)
date_default_timezone_set -- sets the default time zone for all date and time functions in a script
instructions
bool date_default_timezone_set ( string timezone_identifier )
date_default_timezone_set() sets the default time zone for all date and time functions.
Note: since PHP 5.1.0 (this version of the date-time function has been rewritten), each call to the date-time function will generate an E_NOTICE level error message if the time zone is inconsistent.
parameter
timezone_identifier
Time zone identifiers, such as UTC or Europe/Lisbon
The return value
This function always returns TRUE (even if the timezone_identifier parameter is not valid).
-------------------------------------------------------------------------------------
Or modify the value of date.timezone in php.ini
date.timezone = PRC