[Turn] PHP date("Ymd H:i:s"); solution to get the current time difference of 8 hours

Reason:                                                                                               Network resource organization

        Since php5.1.0, the option date.timezone has been added to php.ini, and it is turned off by default, that is, the displayed time (no matter what php command is used) is Greenwich Mean Time and our time (Beijing time). ) by exactly 8 hours.

        The available values ​​for timezone in mainland China are: Asia/Chongqing, Asia/Shanghai, Asia/Urumqi, PRC (Chongqing, Shanghai, Urumqi, the People's Republic of China in turn) available in Hong Kong and Taiwan: Asia/Macao, Asia/Hong_Kong, Asia/ Taipei (in order of Macau, Hong Kong, Taipei) and Singapore: Asia/Singapore Others: Etc/GMT-8, Singapore, Hongkong

Solution one:

        Insert before adding the time: CODE: (it seems that there is no need to add) date_default_timezone_set(PRC);

Solution two:

        echo date("Y-m-d H:i:s", time()+8*60*60);

Solution three (modify the php.ini file):

        Find the line ";date.timezone=" in php.ini, remove the ";", change it to "date.timezone = PRC" (PRC: People's Republic of China), restart Apache, the problem is solved.

 

Attachment: date time format

date("Ymd H:i:s"); Display format: year-month-day hour:minute:second

Related time parameters:

a - "am" or "pm" 
A - "AM" or "PM" 
d - day, two digits, if there are less than two digits, zeros are added in front; for example: "01" to "31" 
D - week Day , three English letters; such as: "Fri" 
F - month, full name in English; such as: "January" 
h - hour in 12-hour format; such as: "01" to "12" 
H - hour in 24-hour format; For example: "00" to "23" 
g - hour in 12-hour format, less than two digits are not filled with zeros; such as: "1" to 12" 
G - hours in 24-hour format, less than two digits are not filled with zeros; such as: " 0" to "23" 
i - minutes; such as: "00" to "59" 
j - days, two digits, if less than two digits are not filled with zeros; such as: "1" to "31" 
l - days of the week, Full name in English; such as: "Friday" 
m - month, two digits, if less than two digits, add zeros in front; such as: "01" to "12" 
n - month, two digits, if less than two digits, no Zero padding; eg: "1" to "12" 
M - month, three English letters; eg: " Jan"
s - seconds; eg: "00" to "59" 
S - suffix with an English ordinal, two English letters; eg: "th", "nd" 
t - days of the specified month; eg: "28" to "31" 
U - total seconds 
w - numeric day of the week, eg: "0" (Sunday) to "6" (Saturday) 
Y - year, four digits; eg: "1999" 
y - year, two digits; eg: "99" 
z - day of the year; eg: "0" to "365"

Reason:                                                                                               Network resource organization

        Since php5.1.0, the option date.timezone has been added to php.ini, and it is turned off by default, that is, the displayed time (no matter what php command is used) is Greenwich Mean Time and our time (Beijing time). ) by exactly 8 hours.

        The available values ​​for timezone in mainland China are: Asia/Chongqing, Asia/Shanghai, Asia/Urumqi, PRC (Chongqing, Shanghai, Urumqi, the People's Republic of China in turn) available in Hong Kong and Taiwan: Asia/Macao, Asia/Hong_Kong, Asia/ Taipei (in order of Macau, Hong Kong, Taipei) and Singapore: Asia/Singapore Others: Etc/GMT-8, Singapore, Hongkong

Solution one:

        Insert before adding the time: CODE: (it seems that there is no need to add) date_default_timezone_set(PRC);

Solution two:

        echo date("Y-m-d H:i:s", time()+8*60*60);

Solution three (modify the php.ini file):

        Find the line ";date.timezone=" in php.ini, remove the ";", change it to "date.timezone = PRC" (PRC: People's Republic of China), restart Apache, the problem is solved.

 

Attachment: date time format

date("Ymd H:i:s"); Display format: year-month-day hour:minute:second

Related time parameters:

a - "am" or "pm" 
A - "AM" or "PM" 
d - day, two digits, if there are less than two digits, zeros are added in front; for example: "01" to "31" 
D - week Day , three English letters; such as: "Fri" 
F - month, full name in English; such as: "January" 
h - hour in 12-hour format; such as: "01" to "12" 
H - hour in 24-hour format; For example: "00" to "23" 
g - hour in 12-hour format, less than two digits are not filled with zeros; such as: "1" to 12" 
G - hours in 24-hour format, less than two digits are not filled with zeros; such as: " 0" to "23" 
i - minutes; such as: "00" to "59" 
j - days, two digits, if less than two digits are not filled with zeros; such as: "1" to "31" 
l - days of the week, Full name in English; such as: "Friday" 
m - month, two digits, if less than two digits, add zeros in front; such as: "01" to "12" 
n - month, two digits, if less than two digits, no Zero padding; eg: "1" to "12" 
M - month, three English letters; eg: " Jan"
s - seconds; eg: "00" to "59" 
S - suffix with an English ordinal, two English letters; eg: "th", "nd" 
t - days of the specified month; eg: "28" to "31" 
U - total seconds 
w - numeric day of the week, eg: "0" (Sunday) to "6" (Saturday) 
Y - year, four digits; eg: "1999" 
y - year, two digits; eg: "99" 
z - day of the year; eg: "0" to "365"

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325376026&siteId=291194637