我收到以下格式的日期 2015-01-09T20:46:00+0100
并需要将其转换为时间戳。
不幸的是, strtotime 函数忽略了时区部分:
print strtotime('2015-01-09T20:46:00+0100') . "\n";
print strtotime('2015-01-09T20:46:00');
//result is the same with or without timezone:
//1420832760
//1420832760
解决这个问题的正确方法是什么?
最佳答案
DateTime 正确处理这个问题:
$date = new DateTime('2015-01-09T20:46:00+0100');
echo $date->getTimestamp();
echo "\n";
$date = new DateTime('2015-01-09T20:46:00');
echo $date->getTimestamp();
1420832760
1420836360
关于php - 将带有时区的日期字符串转换为时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27924003/