首页 > 解决方案 > 在“T”之后使用空格时 php strtotime() 出现意外结果

问题描述

在日期/时间字符串中的“T”之后插入空格时(在 Debian 上使用 PHP 7.1),我注意到 strtotime() 函数的奇怪行为。

我越来越:

strtotime('1970-01-01 00:00:00Z') = 0 //as expected
strtotime('1970-01-01T00:00:00Z') = 0 //as expected
strtotime('1970-01-01 T 00:00:00Z') = 25200 //7 hours more...

strtotime('1970-01-01T00:00:00-12:00') = 43200 //as expected
strtotime('1970-01-01 T 00:00:00-12:00') = 25200 //Same as before...

受影响的行不严格遵守(因为空格)http://php.net/manual/en/datetime.formats.compound.php中报告的格式,一个快速的解决方案是去掉时间字符串中的所有空格,但我对函数的行为感到惊讶:7 小时(25200 秒)从何而来?

标签: phpdatetime-formatstrtotime

解决方案


推荐阅读