Home  >  Article  >  Backend Development  >  PHP solves server US time problem

PHP solves server US time problem

WBOY
WBOYOriginal
2016-07-29 09:15:421130browse
The speed of foreign servers is okay, and there is no need to register or anything. However, I found a problem in the past two days. The time of calling the output is not correct. They are all using American time. This is a problem. For example, today is April. 2nd, but the page shows April 1st, which is not good. I checked the information and found that the code is very easy to use. Share it:

$date = putenv('TZ=America/Chicago ');
mktime(0,0,0,1,1,1970) ;
echo date("Y-m-d H:i:s");

When using it, change "TZ=America/Chicago" to Your local time zone, such as "TZ=Asia/Shanghai"

The above introduces how PHP solves the problem of server US time, including aspects of the problem. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn