首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP strtotime中的奇怪行为

PHP strtotime中的奇怪行为
EN

Stack Overflow用户
提问于 2016-10-17 19:44:18
回答 2查看 58关注 0票数 1
代码语言:javascript
复制
$one   = '2016-10-11';
$two   = '2016-10-13';
$three = '2016-10-15';
$four  = '2016-10-16';
$five  = '2016-10-17';

$output_format = 'Y-m-d H:i:s';

var_dump(
    strtotime($one),
    strtotime($two),
    strtotime($three),
    strtotime($four),
    strtotime($five),
    date($output_format, strtotime($one)),
    date($output_format, strtotime($two)),
    date($output_format, strtotime($three)),
    date($output_format, strtotime($four)),
    date($output_format, strtotime($five))
); 

这输出

代码语言:javascript
复制
int 1476154800

int 1476327600

int 1476500400

int 1476586800

int 1476669600

string '2016-10-11 00:00:00' (length=19)

string '2016-10-13 00:00:00' (length=19)

string '2016-10-15 00:00:00' (length=19)

string '2016-10-16 01:00:00' (length=19)

string '2016-10-17 00:00:00' (length=19)

为什么“2016-10-16 01:00”有01:00而其他人有00:00?我使用的是PHP 5.5.29。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-10-17 20:00:42

这与“夏令节约时间”(DST)有关。我的php.ini时区当前设置为

代码语言:javascript
复制
date.timezone = America/Sao_Paulo

在巴西,我们在2016-10-16年进入了“夏令时间”(DST),所以它有01:00:00。有意思,这是我多年来第一次想到这件事。

票数 1
EN

Stack Overflow用户

发布于 2016-10-17 20:00:52

这个问题的作者似乎是住在巴西,在巴西,DST实际上发生在2016年10月16日- https://www.timeanddate.com/time/change/brazil/brasilia?year=2016

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40094427

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档