RFC 3339如何制作dateTime [英] RFC 3339 how make a dateTime from

查看:348
本文介绍了RFC 3339如何制作dateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试格式化从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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆