|
|
朝气蓬勃的豆浆 · Mac上MD5校验工具如何验证文件完整性?_ ...· 3 月前 · |
|
|
慷慨的葡萄酒 · 解密千年谎言:人养玉玉养人_藏趣逸闻_新浪收 ...· 1 年前 · |
|
|
飞奔的蚂蚁 · 金华经济技术开发区简介· 1 年前 · |
|
|
儒雅的红豆 · 对十三届全国人大三次会议第2919号建议的答 ...· 1 年前 · |
|
|
儒雅的薯片 · 京东接口h5st生成规则逆向之x-api-e ...· 2 年前 · |
|
|
阳刚的煎鸡蛋 · C++头文件编译问题-阿里云开发者社区· 2 年前 · |
如何将时间从
2010-12-30 23:21:46
转换为ISO8601日期格式?(-_-;)
面向对象
这是推荐的方式。
$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'));
在PHP5之后,你可以使用这个:
echo date("c");
form ISO8601格式的日期时间。
备注:
关于时区,这两个表达式对于基本格式:
±[hh]:[mm], ±[hh][mm], or ±[hh]
的时区都有效。
但请注意,+0X:00是正确的,而+0X00对于扩展使用是不正确的。所以最好使用
date("c")
。类似的讨论
here
。
如何将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');