Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that PHP got the wrong time through date () function

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to solve the problem that PHP got the wrong time through date () function". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to solve the problem that PHP got the wrong time through the date () function.

PHP got the time error through the date () function

To get straight to the topic, after obtaining the time through the date () function, you will find that the hour time is wrong, 8 hours less than the current time, whether using H or h, this is because the current acquisition is Greenwich time, the difference between Beijing time and Beijing time is 8 hours.

The solution is as follows:

1. Modify php.ini configuration file

Open the php.ini file and find it in the root directory of the php configuration. Date.timezone, delete the semicolon and change it to date.

Timezone = PRC. Save and restart the Apahce service (sometimes there will be problems with restart, just stop and then start).

2. Add the date_default_timezone_set (timezone_identifier) function

What this function means is to set the current time zone, initialize the time, and add this sentence before the header or get time statement.

For example:

Date_default_timezone_set (PRC)

Echo date ("Y-m-d H-i-s")

The parameters are set as follows:

Date_default_timezone_set (PRC)-set to Beijing time, PRC represents the people's Republic of China

Date_default_timezone_set ('Asia/Shanghai')-set to Shanghai time, and' Chongqi' (Chongqing) and 'Urumqi' (Urumqi) are also available on the mainland.

Available in Hong Kong and Taiwan: Asia/Macao, Asia/Hong_Kong, Asia/Taipei

(followed by Macao, Hong Kong and Taipei)

Singapore area: Asia/Singapore (I don't seem to see Beijing)

This function will always return True, but be sure to enter timezone_identifier, otherwise an error will be reported.

Here are all the time zone identifiers: (for your reference)

CET

CST6CDT

Cuba

EET

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

At this point, I believe you have a deeper understanding of "how to solve the problem that PHP got the wrong time through the date () function". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report