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

What will happen if the php time zone is not changed?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the impact of not changing the php time zone, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Not changing the php time zone will cause the time of entering the database and the time of acquisition to be different from the actual time. The solution is: 1, change the "data.timezone = PRC" in the php.ini file; 2, add "data_default_timezone_set ('PRC');".

This article operating environment: windows7 system, PHP7.4 version, DELL G3 computer

Not changing the php time zone will cause the time of entering the database and the time of acquisition to be different from the actual time.

The solution to the time Zone problem encountered in PHP

Recently, when writing a Mini Program with PHP+MySQL, I found a problem: the difference between the time of entering the database and the actual time is 8 hours, which is consistent with the East 8 District of China. Since the database time is written by PHP, the problem occurs in PHP.

Recently, in the process of learning PHP, it was found that the formatting timestamp in PHP was 8 hours later than Beijing time. Online search found that it was the wrong time zone. The solution is:

1. Permanent modification

Change data.timezone = PRC in the php.ini file. This is China time. It takes effect after the Apache service is restarted.

2. Temporary modification

Add ini_set ('date.timezone','Asia/Shanghai') before entering time using formatting

Or the data_default_timezone_set ('PRC') / / date_default_timezone_set () function sets the default time zone for all date / time functions in the script.

Look at the problems encountered by other partners.

There was a remaining problem before, that is, the return time of echo date ("Y-m-d H:i:s", time ()) is always out of line with the actual time. Today, we finally found the reason and solution on the Internet, sharing as follows:

Add a point, according to the following tips to modify the php.ini can not find date.timezone this line, is there no way, of course not, , if not, then add it yourself, do your own food and clothing. With the addition of such a sentence date.timezone = "PRC", the problem is solved. Happy.

Starting with php5.1.0, date.timezone is added to php.ini, which is turned off by default

That is, the time displayed (no matter what php command is used) is Greenwich mean time, which is exactly 8 hours short of our time (Beijing time). There are three ways to return to normal time.

1. The easiest way is not to use a version above php5.1

2. If you must use it and you cannot modify php.ini, you need to add date_default_timezone_set (XXX) to the initialization statement about time.

3, once and for all, only php.ini can be modified. Open php.ini to find date.timezone and remove the previous semicolon

= add XXX after it, restart the http service (such as apache2 or iis, etc.)

Thank you for reading this article carefully. I hope the article "what will be the impact of not changing the php time zone" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you 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