PHP——秒转换为天 | 小时 | 分钟
Posted wangyang0210
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP——秒转换为天 | 小时 | 分钟相关的知识,希望对你有一定的参考价值。
前言
通讯记录需要用到的一个方法,记录下~
方法
/** * 秒转换为天,小时,分钟 * * @param int $second * * @return string */ function secondConversion($second = 0) { $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; }
以上是关于PHP——秒转换为天 | 小时 | 分钟的主要内容,如果未能解决你的问题,请参考以下文章