search
Homephp教程php手册PHP里的“夏令虫”

今儿,我遇到一个大怪物 -- 夏令虫

╮(╯▽╰)╭,学艺不精,因为他掉进大坑里去了。坑是这样挖的:

以前,我为了表示当前时间的“明天”、“后天”,会用到类如下面的写法:

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

殊不知,这种写法并不安全的,请看例子:


 

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);

输出的结果是


 

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

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


第二天被偷偷吃掉一个小时!

而且未来154天都会这样,直到第155天,这一小时才会“被还回来”。

为什么会这个样子?通过查询资料发现,原来是夏令时导致的问题,

不过,我国当前未实行夏令时,所以,这个问题对于“Asia/Shanghai”来说,暂时不会成为问题。

关于日期的格式化,还是推荐寻找使用更科学的计算方式。

 


以前写的PHP代码都有可能会因此而BUG,在这里向以前的项目致歉了。

 

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools