如何
在 PHP 中将2012-01-18T11:45:00+01:00
(ISO 8601) 转换为1326883500
(unixtimestamp)?
问问题
35882 次
2 回答
64
echo date("U",strtotime('2012-01-18T11:45:00+01:00'));
于 2012-01-18T10:50:52.200 回答
19
从 ISO 8601 转换为 unixtimestamp :
strtotime('2012-01-18T11:45:00+01:00');
// Output : 1326883500
从 unixtimestamp 转换为 ISO 8601(时区服务器):
date_format(date_timestamp_set(new DateTime(), 1326883500), 'c');
// Output : 2012-01-18T11:45:00+01:00
要将 unixtimestamp 转换为 ISO 8601 (GMT):
date_format(date_create('@'. 1326883500), 'c') . "\n";
// Output : 2012-01-18T10:45:00+00:00
从 unixtimestamp 转换为 ISO 8601(自定义时区):
date_format(date_timestamp_set(new DateTime(), 1326883500)->setTimezone(new DateTimeZone('America/New_York')), 'c');
// Output : 2012-01-18T05:45:00-05:00
于 2016-02-20T12:45:05.390 回答