php将秒转化为时间格式的方法:1、创建一个php示例文件;2、定义一个“private function convert($second){...}”方法;3、在方法体内通过“floor($second / (3600*24));”等公式实现秒数转换为时间即可。
本教程操作环境:Windows7系统、PHP8.1版、Dell G3电脑。
php怎么将秒转化为时间格式
php- 秒的转换 (天 小时 分钟) (小时 分钟 )
php 秒 转换为 天 小时 分钟 小时 分钟
代码如下:
private function convert($second)
{
$newtime = '';
$d = floor($second / (3600*24));
$h = floor(($second % (3600*24)) / 3600);
$m = floor((($second % (3600*24)) % 3600) / 60);
if ($d>'0') {
if ($h == '0' && $m == '0') {
$newtime= $d.'天';
} else {
$newtime= $d.'天'.$h.'小时'.$m.'分钟';
}
} else {
if ($h!='0') {
if ($m == '0') {
$newtime= $h.'小时';
} else {
$newtime= $h.'小时'.$m.'分';
}
} else {
$newtime= $m.'分';
}
}
return $newtime;
}