Home > Article > Backend Development > "Summer Bug" in PHP_PHP Tutorial
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('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);
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.