Home >Backend Development >PHP Tutorial >2016年3月13日这一天不等于3600*24秒?

2016年3月13日这一天不等于3600*24秒?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 20:16:191549browse

在工作中发现一个bug:

我公司服务器的php的default timezone 和 timezone 都配置为 America/Los_Angeles;

时间戳 1457856000,

使用date()函数格式化后是2016-03-13 00:00:00;

但是为该时间戳加上3600*24-1秒后,使用date()函数格式化发现居然是2016-03-14 00:59:59;

而该日期的前一天和后一天则没有这种诡异的现象;

有人知道这是什么原因吗?

回复内容:

在工作中发现一个bug:

我公司服务器的php的default timezone 和 timezone 都配置为 America/Los_Angeles;

时间戳 1457856000,

使用date()函数格式化后是2016-03-13 00:00:00;

但是为该时间戳加上3600*24-1秒后,使用date()函数格式化发现居然是2016-03-14 00:59:59;

而该日期的前一天和后一天则没有这种诡异的现象;

有人知道这是什么原因吗?

<code>/**
 * 按照你说的时间,应该就是这个时区,
 * 但是没什么问题,是你的计算过程出现什么没有注意到的地方, 还是不同的时区的关系
 */
date_default_timezone_set('Etc/GMT+8');
$timeStamp = 1457856000;
var_dump(date('Y-m-d H:i:s', $timeStamp));
var_dump(date('Y-m-d H:i:s', $timeStamp + 3600*24-1));</code>

2016年3月13日这一天不等于3600*24秒?

不是很懂你的问题……初步怀疑是因为其他的计算导致的。
2016年3月13日这一天不等于3600*24秒?

有个概念叫做夏令时~

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