GDATA Feed API - 在 PHP 中解析时间戳

发布于 2024-11-19 07:17:47 字数 343 浏览 4 评论 0原文

我目前正在使用 YouTube 的 feed API 来获取有关 YouTube 频道上传的视频的信息。 Feed 示例类似于 http://gdata.youtube。 com/feeds/api/users/google/uploads?v=2

Feed 中的时间戳采用以下格式2011-04-27T20:54:42.000Z。我如何将其转换为更具可读性的内容,例如 2011 年 4 月 27 日晚上 8:54:42

I'm currently using YouTube's feed API to get information about a YouTube channel's uploaded videos. An example feed would be something like http://gdata.youtube.com/feeds/api/users/google/uploads?v=2

Timestamps in the feed are in the format 2011-04-27T20:54:42.000Z. How would I convert that to something more readable, like April 27th, 2011 at 8:54:42pm?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

╰沐子 2024-11-26 07:17:47

使用 DateTime::createFromFormat 从该格式创建一个新的 DateTime 对象,然后您可以使用该对象的 format 方法以您想要的方式输出它。

Use DateTime::createFromFormat to create a new DateTime object from that format, then you can output it however you want using the object's format method.

青芜 2024-11-26 07:17:47

您可以使用 strtotime 的组合,它将字符串转换为 UNIX 时间戳,和 date,它将时间戳转换为人类可读的输出:

echo date( 'F dS, Y \a\t h:i:sa', strtotime("2011-04-27T20:54:42.000Z") );

实例

You can use a combination of strtotime, which converts a string into a UNIX timestamp, and date, which converts a timestamp into human-readable output:

echo date( 'F dS, Y \a\t h:i:sa', strtotime("2011-04-27T20:54:42.000Z") );

Live example

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文