Home > Backend Development > PHP Tutorial > The time of php time() and date() is different from that of the local computer_PHP tutorial

The time of php time() and date() is different from that of the local computer_PHP tutorial

WBOY
Release: 2016-07-13 10:43:12
Original
909 people have browsed it

My classmates often ask me why the time of php time() and date() is different from that of the local computer. How many hours are there? If you calculate it carefully, there is a difference of 8 hours. This is a problem with the time zone setting of php date_default_timezone_set , we just need to set it up simply.

The time of php time() and date() is different from that of the local computer_PHP tutorial

If the date time is inconsistent, you can use date_default_timezone_set to set the time zone:

The code is as follows
 代码如下 复制代码
";   //对当前时间进行计算 echo date('Y-m-d H:i:s',time()-600); //减10小时 echo "
";   //时间戳转时间 echo date('Y-m-d H:i:s',1364277600);   //时间转时间戳(仅精确到秒) echo strtotime("2013-03-26 14:00"); echo "
";  

?>

Copy code

"; ​ //Calculate the current time echo date('Y-m-d H:i:s',time()-600); //Subtract 10 hours echo "
"; ​ //Timestamp to time echo date('Y-m-d H:i:s',1364277600); ​ //Convert time to timestamp (accurate to seconds only) echo strtotime("2013-03-26 14:00"); echo "
"; ​
 代码如下 复制代码

date.timezone = PRC

?>

In addition to the above method, we can also set a time zone in php.ini, so that in the future there will be no need to add date_default_timezone_set('Asia/Chongqing'); in the program

The code is as follows Copy code
date.timezone = PRC http://www.bkjia.com/PHPjc/633191.html
www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633191.htmlTechArticleSome students often ask me why php time() and date() time are different from the local computer, related How many hours are there? If you calculate carefully, there is a difference of 8 hours. This is php date_default_tim...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template