Home  >  Article  >  Backend Development  >  "Summer Bug" in PHP_PHP Tutorial

"Summer Bug" in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-14 10:12:23991browse

Today, I met a big monster -- the summer bug

╮(╯▽╰)╭, he is not good at learning because he fell into a big pit. This is how the hole was dug:

In the past, in order to express "tomorrow" and "the day after tomorrow" at the current time, I would use writing methods like the following:

$date = date(time + 3600*24*N);

As everyone knows, this way of writing is not safe. Please see the example:


ini_set('date.timezone','Europe/Berlin'); 
echo date("Y-m-d H:i:s",1382824800); 
echo "<br/>"; 
echo date("Y-m-d H:i:s",1382824800 + 1*86400); 

ini_set(&#39;date.timezone&#39;,&#39;Europe/Berlin&#39;);
echo date("Y-m-d H:i:s",1382824800);
echo "<br/>";
echo date("Y-m-d H:i:s",1382824800 + 1*86400);

The output result is


2013-10-27 00:00:00 
2013-10-27 23:00:00 

2013-10-27 00:00:00
2013-10-27 23:00:00


I was secretly eaten for an hour the next day!

And it will be like this for the next 154 days. This hour will not be "returned" until the 155th day.

Why is it like this? After querying the data, I found that the problem was caused by daylight saving time,

However, our country currently does not implement daylight saving time, so this problem will not be a problem for "Asia/Shanghai" for the time being.

Regarding date formatting, it is recommended to find a more scientific calculation method.


The PHP code written before may have bugs due to this, so I would like to apologize to previous projects.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477171.htmlTechArticleToday, I encountered a big monster - summer bug ╮(╯▽╰)╭, who is not good at learning. , because he fell into a big pit. The hole is dug like this: In the past, in order to express the current time tomorrow...
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