PHP strtotime 认为 24h 输入是 12h?
PHP strtotime thinks 24h input is 12h?
strtotime('31.07.2017 08:17')
输出为 1501478160
正好 12h 比它应该的 (31.07.2017 08:17pm UTC+02:00) 但既然我给的是军事时间,那么应该是 08:17 早上吧!
我已经正确设置了所有 time zones
。
我在这里错过了什么?我如何告诉 strtotime
我想将时间设置为 24 小时格式?
谢谢
strtotime
涉及一些猜测来弄清楚您的输入的含义。我自己测试了一下,得到了08:17
(AM),所以可能是locale设置有问题。
无论如何,如果您知道格式,那么您应该更喜欢 DateTime::createFromFormat()
并准确地告诉它期望的内容:
$dt = DateTime::createFromFormat('!d.m.Y H:i','31.07.2017 08:17');
您现在可以对该对象执行各种操作,最终:
echo $dt->format('Y-m-d\TH:i:s'); // or whatever format you want
只需更换
strtotime('31.07.2017 08:17');
和
strtotime('31.07.2017 08:17PM');
并再次检查。
只需在 String
中提及 AM 或 PM
strtotime('31.07.2017 08:17')
输出为 1501478160
正好 12h 比它应该的 (31.07.2017 08:17pm UTC+02:00) 但既然我给的是军事时间,那么应该是 08:17 早上吧!
我已经正确设置了所有 time zones
。
我在这里错过了什么?我如何告诉 strtotime
我想将时间设置为 24 小时格式?
谢谢
strtotime
涉及一些猜测来弄清楚您的输入的含义。我自己测试了一下,得到了08:17
(AM),所以可能是locale设置有问题。
无论如何,如果您知道格式,那么您应该更喜欢 DateTime::createFromFormat()
并准确地告诉它期望的内容:
$dt = DateTime::createFromFormat('!d.m.Y H:i','31.07.2017 08:17');
您现在可以对该对象执行各种操作,最终:
echo $dt->format('Y-m-d\TH:i:s'); // or whatever format you want
只需更换
strtotime('31.07.2017 08:17');
和
strtotime('31.07.2017 08:17PM');
并再次检查。
只需在 String