我正在尝试格式化从google plus Api传出的日期,就像RFC 3339格式的指南一样:
I'm trying to format a date passed from a google plus Api thats like the guide says in RFC 3339 format:
PUBLISHED - > datetime->此活动最初发布的时间。格式化为RFC 3339时间戳。
PUBLISHED-> datetime-> The time at which this activity was initially published. Formatted as an RFC 3339 timestamp.
所以通过php文档我发现:
So by php documentation i found that:
DATE_RFC3339 与DATE_ATOM相同(自PHP 5.1.3起)
DATE_RFC3339 Same as DATE_ATOM (since PHP 5.1.3)
两种格式都是这样的:
Ymd\TH:i:sP
"Y-m-d\TH:i:sP"
实际上,Google api的输出类似于:
Actually the output of the Google api is something like:
2014-01-22T10: 36:00.222Z
2014-01-22T10:36:00.222Z
当我尝试启动命令,如:
When I'm trying to launch command like:
$date = DateTime::createFromFormat("Y-m-d\TH:i:sP", $activity['published']); //$activity['published'] contain the date我一直都是 FALSE 作为回报。 在我看来,问题在最后部分
I have always FALSE as return. In my opinion the problem is in the final part
.222Z
.222Z
任何建议将在通过一些初步方法切割之前得到欣赏。
any suggestion will be appreciate before cutting it by some rudimental approach...
推荐答案您不需要为标准输入使用 DateTime :: createFromFormat()。只需使用:
You don't need to use DateTime::createFromFormat() for standard inputs. Just use:
$date = new DateTime('2014-01-22T10:36:00.222Z'); var_dump($date);
But if you still insist to use createFromFormat(), then use correct format, with microseconds:
$date = DateTime::createFromFormat('Y-m-d\TH:i:s.uP', '2014-01-22T10:36:00.222Z'); var_dump($date);更多推荐
RFC 3339如何制作dateTime
发布评论