开发者

GDATA Feed API - Parsing Timestamps in PHP

开发者 https://www.devze.com 2023-03-18 20:30 出处:网络
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?

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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消