/**
* 把HH:MM:SS格式的時間字符串轉換成秒數,可以使用date_parse函數解析具體的時間信息。
* @param $time
* @return float|int|mixed 反回秒數
* 2020/5/29
* 22:10
*/
function changeTimeFormat($time='')
{
if (empty($time)){
$time=date('H:i:s',time());
}
$count=count(explode(':',$time));
if ($count==2){
$time='00:'.$time;
}elseif($count==1){
$time='00:00:'.$time;
}
$parsed = date_parse($time);
$seconds = $parsed['hour'] * 3600+$parsed['minute'] * 60+$parsed['second'];
return $seconds;
}
/**
* $seconds = 3600*34 + 122;
* @param $seconds
* @return string 返回 時:分:秒 | 分:秒 | 秒
* 2020/5/29
* 21:51
*/
function changeTimeTypes($seconds){
if ($seconds >= 3600){
$hours = intval($seconds/3600);
$minutes = $seconds % 3600;
$time = $hours.":".gmstrftime('%M:%S', $minutes);
}else{
if ($seconds>=60){
// $time = gmstrftime('%H:%M:%S', $seconds);
$time = gmstrftime('%M:%S', $seconds);
}else{
$time = gmstrftime('%S', $seconds);
}
}
return $time;
}