如何在YouTube中将youtube视频发布日期转换为DD/MM/YY?

use*_*287 6 php datetime youtube-api

我使用以下内容获取YouTube视频的发布日期:

$url = "http://gdata.youtube.com/feeds/api/videos/{$random_text}?v=2&alt=json";
$json = file_get_contents($url);
$json = str_replace('$', '_', $json);
$obj = json_decode($json);
$video_date = $obj->entry->published->_t;
Run Code Online (Sandbox Code Playgroud)

以这种格式输出日期:

2012-10-18t13:04:42.000z

我怎么能在PHP中将其转换为DD/MM/YY格式?

我尝试过以下解决方案:

这是什么时间格式,如何将其转换为标准化的dd/mm/yyyy日期?

$video_date_pre = $obj->entry->published->_t;
// format the video date
$video_date = date_format($video_date_pre, 'd/m/Y');
Run Code Online (Sandbox Code Playgroud)

但我收到错误:

警告:date_format()期望参数1为DateTime ..

谢谢.

更新

可能有必要注意原始源看起来像这样(您可以在其中搜索"已发布"):

http://gdata.youtube.com/feeds/api/videos/eiAx2kqmUpQ?v=2&alt=json

Ste*_*rex 8

试试这个:

$video_date = date('d/m/y', strtotime($video_date_pre));
Run Code Online (Sandbox Code Playgroud)

在此解决方案中,您需要先将字符串转换为Unixtime,然后才能使用date()函数.

http://php.net/manual/en/function.strtotime.php

http://www.php.net/manual/en/function.date.php

或者您可以使用DateTime对象:

$dateObject = new DateTime($video_date_pre);
$video_date = date_format($dateObject , 'd/m/y');
Run Code Online (Sandbox Code Playgroud)