我们在处理时间时,需要计算当前时间距离某个时间点的时长,如计算客户端运行时长,通常用hh:mm:ss表示。
1 function changeTimeType( $seconds ) { 2 3 if ( $seconds > 3600 ) { 4 5 $hours = intval ( $seconds / 3600 ); 6 7 $minutes = $seconds % 3600 ; 8 9 $time = $hours . ":" . gmstrftime ('%M:%S', $minutes ); 10 11 } else { 12 13 $time = gmstrftime ('%H:%M:%S', $seconds ); 14 15 } 16 17 return $time ; 18 19 } 20 21 // 使用方法如下 22 23 $seconds = 3712 ; 24 25 echo changeTimeType( $seconds );
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did29803