转换视频时间
$json_array = file_get_contents("https://graph.facebook.com/v2.12/$PID[$FID]/videos?fields=title,length,from,description,created_time,source&limit=10&access_token=");
$json_data=json_decode($json_array,true);
foreach($json_data['data'] as $links){
$video_time = $links['length'];
238.142 这次转换 3.57
答案 0 :(得分:0)
以下是算法:
.142
无关紧要,因为您似乎只需要分钟和秒数
要计算秒数,请将模数计算为60
238 % 60 = 58
要计算分钟数,请从总时间中删除秒数并除以60
(238 - 58) / 60 = 3
=> 3分58秒
答案 1 :(得分:0)
为此,您只需使用gmdate()
功能
echo gmdate("H:i:s", 238.142); //output: 00:03:58
echo gmdate("H.i.s", 238.142); //output: 00.03.58
echo gmdate("i.s", 238.142); //output: 03.58
答案 2 :(得分:0)
function vtime($lenth){
$seconds = $lenth;
$hours = floor($seconds / 3600);
$seconds -= $hours * 3600;
$minutes = floor($seconds / 60);
$seconds -= $minutes * 60;
if($hours == 0){ return "$minutes:$seconds"; }
elseif($minutes == 0){ return $seconds; }
else { return "$hours:$minutes:$seconds"; }
}
echo vtime('304');