php 将 ISO 8601 转换为 unixtimestamp
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8908797/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 05:46:24 来源:igfitidea点击:
Convert ISO 8601 to unixtimestamp
提问by Codler
How can I convert
2012-01-18T11:45:00+01:00
(ISO 8601) to 1326883500
(unixtimestamp) in PHP?
如何在 PHP 中将2012-01-18T11:45:00+01:00
(ISO 8601)转换
为1326883500
(unixtimestamp)?
回答by k102
echo date("U",strtotime('2012-01-18T11:45:00+01:00'));
回答by John Slegers
To convert from ISO 8601 to unixtimestamp :
要将 ISO 8601 转换为 unixtimestamp :
strtotime('2012-01-18T11:45:00+01:00');
// Output : 1326883500
To convert from unixtimestamp to ISO 8601 (timezone server) :
要将 unixtimestamp 转换为 ISO 8601(时区服务器):
date_format(date_timestamp_set(new DateTime(), 1326883500), 'c');
// Output : 2012-01-18T11:45:00+01:00
To convert from unixtimestamp to ISO 8601 (GMT) :
要将 unixtimestamp 转换为 ISO 8601 (GMT):
date_format(date_create('@'. 1326883500), 'c') . "\n";
// Output : 2012-01-18T10:45:00+00:00
To convert from unixtimestamp to ISO 8601 (custom timezone) :
要将 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