2011-03-28 91 views
0

任何人都可以请解释如何解析日期IETF RFC 3339在PHP中,在最方便的方法。以上格式的日期示例为:2011-03-14T06:25:22 + 0000解析日期IETF RFC 3339在php

谢谢!!

+0

我会说'new DateTime('2011-03-14T06:25:22 + 0000');' – Wrikken 2011-03-28 21:09:30

回答

0

使用strtotime()date() ...

<?php 
    // source date 
    $source = strtotime('2011-03-14T06:25:22+0000'); 

    // remove this line to use your server's local time 
    date_default_timezone_set('UTC'); 

    // parse and print 
    echo date('Y-m-d h:i.s A O', $source); 
?> 

输出:

2011-03-14 06:25.22 AM +0000 
1

至少为PHP 5.3的,该格式原生strtotimedate_create支持。从PHP交互shell使用日期时间:

php > $d = date_create('2011-03-14T06:25:22+0000'); 
php > echo $d->format('Y-m-d H:i:s'); 
2011-03-14 06:25:22 
php > echo $d->getTimezone()->getName(); 
+00:00 

你可能会想在all of the formats these two functions support阅读起来。

+0

此格式在PHP 5.0及更新版本中支持 – drudge 2011-03-28 21:21:33