abstract:本文實(shí)例講述了PHP自定義函數(shù)實(shí)現(xiàn)格式化秒的方法。分享給大家供大家參考,具體如下:function vtime($time) { $output = ''; foreach (array(86400 => '天', 3600 
本文實(shí)例講述了PHP自定義函數(shù)實(shí)現(xiàn)格式化秒的方法。分享給大家供大家參考,具體如下:
function vtime($time) { $output = ''; foreach (array(86400 => '天', 3600 => '小時(shí)', 60 => '分', 1 => '秒') as $key => $value) { if ($time >= $key) $output .= floor($time/$key) . $value; $time %= $key; } if($output==''){ $output=0; } return $output; } //$now=time(); $oldtime=86465; //echo vtime($now);//輸出:17058天4小時(shí)8分55秒 echo vtime($oldtime);//輸出:1天1分5秒
更多關(guān)于PHP自定義函數(shù)實(shí)現(xiàn)格式化秒的方法請(qǐng)關(guān)注PHP中文網(wǎng)(www.miracleart.cn)其它文章!