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

Jul 13, 2016 am 10:43 AM
date php time and Why classmate time There is a difference local computer

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...
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to fine-tune deepseek locally How to fine-tune deepseek locally Feb 19, 2025 pm 05:21 PM

How to fine-tune deepseek locally

deepseek why can't you log in deepseek login portal deepseek why can't you log in deepseek login portal Feb 19, 2025 pm 05:00 PM

deepseek why can't you log in deepseek login portal

deepseek image generation tutorial deepseek image generation tutorial Feb 19, 2025 pm 04:15 PM

deepseek image generation tutorial

Pi Node Teaching: What is a Pi Node? How to install and set up Pi Node? Pi Node Teaching: What is a Pi Node? How to install and set up Pi Node? Mar 05, 2025 pm 05:57 PM

Pi Node Teaching: What is a Pi Node? How to install and set up Pi Node?

How to ask deepseek How to ask deepseek Feb 19, 2025 pm 04:39 PM

How to ask deepseek

Why can't the Bybit exchange link be directly downloaded and installed? Why can't the Bybit exchange link be directly downloaded and installed? Feb 21, 2025 pm 10:57 PM

Why can't the Bybit exchange link be directly downloaded and installed?

How to download deepseek How to download deepseek Feb 19, 2025 pm 05:45 PM

How to download deepseek

How to use deepseek How to use deepseek Feb 19, 2025 pm 04:45 PM

How to use deepseek

See all articles