有人可以告诉我如何在PHP中将特定时间戳转换为天 - 小时 - 分钟?
例如,我想从这样的随机时间戳得到这样的东西:( 20天13小时35分钟):534222234
谢谢.
function time2string($time) {
$d = floor($time/86400);
$_d = ($d < 10 ? '0' : '').$d;
$h = floor(($time-$d*86400)/3600);
$_h = ($h < 10 ? '0' : '').$h;
$m = floor(($time-($d*86400+$h*3600))/60);
$_m = ($m < 10 ? '0' : '').$m;
$s = $time-($d*86400+$h*3600+$m*60);
$_s = ($s < 10 ? '0' : '').$s;
$time_str = $_d.':'.$_h.':'.$_m.':'.$_s;
return $time_str;
}
Run Code Online (Sandbox Code Playgroud)
使用示例:
echo time2string(86500); // 01:00:01:40 dd:hh:mm:ss
Run Code Online (Sandbox Code Playgroud)