php - 秒数的转换 (年 天 小时 分钟 秒)
/**
*秒数转换:年 天 小时 分钟 秒
* @param $second
* @return bool|string
*/
function second_time($second)
{
if (!is_numeric($second)) {
return false;
}
$dataTime = array(
"years" => 0,
"days" => 0,
"hours" => 0,
"minutes" => 0,
"seconds" => 0,
);
if ($second >= 31556926) {
$dataTime["years"] = floor($second / 31556926);
$second = ($second % 31556926);
}
if ($second >= 86400) {
$dataTime["days"] = floor($second / 86400);
$second = ($second % 86400);
}
if ($second >= 3600) {
$dataTime["hours"] = floor($second / 3600);
$second = ($second % 3600);
}
if ($second >= 60) {
$dataTime["minutes"] = floor($second / 60);
$second = ($second % 60);
}
$dataTime["seconds"] = floor($second);
$time = $dataTime["years"] . "年" . $dataTime["days"] . "天" . " " . $dataTime["hours"] . "小时" . $dataTime["minutes"] . "分" . $dataTime["seconds"] . "秒";
return $time;
}
php - 秒数转换 (天 小时 分钟 秒) (小时 分钟 秒)
/**
* 秒数转换:天 小时 分钟 秒
* @param $second
* @return string
*/
function convert($second)
{
$newtime = '';
$d = floor($second / (3600 * 24));
$h = floor(($second % (3600 * 24)) / 3600);
$m = floor((($second % (3600 * 24)) % 3600) / 60);
$s = floor($second % 60);
if ($d > '0') {
if ($h == '0' && $m == '0') {
$newtime = $d . '天';
} else {
$newtime = $d . '天' . $h . '小时' . $m . '分钟' . $s . '秒';
}
} else {
if ($h != '0') {
if ($m == '0') {
$newtime = $h . '小时';
} else {
$newtime = $h . '小时' . $m . '分' . $s . '秒';
}
} else {
$newtime = $m . '分' . $s . '秒';
}
}
return $newtime;
}
网友评论