我的表中有一个总秒值,但我想得到一个时间格式,例如hh:mm:ss
,目前我有:seconds - 226
而且我知道应该是 4 分 26 秒的时间格式,但我试过这段代码:
$seconds = 226;
$hours = floor($seconds / 3600);
$mins = floor(($seconds - ($hours*3600)) / 60);
$secs = floor(($seconds - ($hours*3600)) - ($mins*60));
这输出3:46
也许公式有问题?
编辑:我从一个返回视频持续时间的 youtube 脚本中得到了这个值:
$ytvidid = $url;
$ytdataurl = "http://gdata.youtube.com/feeds/api/videos/". $ytvidid;
$feedURL = $ytdataurl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $feedURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// get the result of http query
$output = curl_exec($ch);
curl_close($ch);
// feed the curl output to simplexml_load_string
$sxml = simplexml_load_string($output) or die("XML string not loading");
//$sxml = simplexml_load_file($feedURL);
$media = $sxml->children('http://search.yahoo.com/mrss/');
// get <yt:duration> node for video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
echo $attrs['seconds'];