如何将时间从2010-12-30 23:21:46
转换为ISO8601日期格式?(-_-;)
发布于 2011-03-16 15:42:14
面向对象
这是推荐的方式。
$datetime = new DateTime('2010-12-30 23:21:46');
echo $datetime->format(DateTime::ATOM); // Updated ISO8601
程序化
对于旧版本的PHP,或者如果您更习惯使用过程代码。
echo date(DATE_ISO8601, strtotime('2010-12-30 23:21:46'));
发布于 2012-06-24 05:17:54
在PHP5之后,你可以使用这个:echo date("c");
form ISO8601格式的日期时间。
备注:
关于时区,这两个表达式对于基本格式:±[hh]:[mm], ±[hh][mm], or ±[hh]
的时区都有效。
但请注意,+0X:00是正确的,而+0X00对于扩展使用是不正确的。所以最好使用date("c")
。类似的讨论here。
发布于 2017-04-04 02:32:15
如何将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
https://stackoverflow.com/questions/5322285
复制相似问题