【发布时间】:2014-02-18 10:09:17
【问题描述】:
我正在尝试格式化从 google plus Api 传递的日期,就像指南在 RFC 3339 格式中所说的那样:
PUBLISHED-> datetime-> 此活动最初发布的时间。格式化为 RFC 3339 时间戳。
所以通过 php 文档我发现:
DATE_RFC3339 与 DATE_ATOM 相同(自 PHP 5.1.3 起)
这两种格式都类似于:
"Y-m-d\TH:i:sP"
实际上 Google api 的输出是这样的:
2014-01-22T10:36:00.222Z
当我尝试启动如下命令时:
$date = DateTime::createFromFormat("Y-m-d\TH:i:sP", $activity['published']); //$activity['published'] contain the date
我总是以FALSE 作为回报。
在我看来,问题出在最后一部分
.222Z
任何建议在通过一些基本方法削减之前都会受到赞赏......
【问题讨论】:
-
或者使用标准的
date()方法:date( DATE_RFC3339, $activity['published'] );
标签: php datetime google-plus rfc3339