RFC 3339如何制作dateTime

编程入门 行业动态 更新时间:2024-10-27 08:29:54
本文介绍了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

本文发布于:2023-11-03 16:52:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555613.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:RFC   dateTime

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!