php将秒数转换成时分秒的方法:1、通过“function changeTimeType($seconds){…}”方法将秒数转换成时分秒;2、通过“function Sec2Time($time){…}”方法将秒数转换成年天时分秒。
本文操作环境:Windows7系统、PHP7.1版本、Dell G3电脑
php怎么将秒数转换成时分秒?
PHP将秒数转换成时分秒
一:
/** * 将秒数转换成时分秒 * * @param 秒数 $seconds * @return void */ function changeTimeType($seconds) { if ($seconds > 3600) { $hours = intval($seconds / 3600); $time = $hours . ":" . gmstrftime('%M:%S', $seconds); } else { $time = gmstrftime('%H:%M:%S', $seconds); } return $time; }
二:
/** * 转换成 年 天 时 分 秒 * * @param [type] $time * @return void */ function Sec2Time($time) { if (is_numeric($time)) { $value = array( "years" => 0, "days" => 0, "hours" => 0, "minutes" => 0, "seconds" => 0, ); $t = ''; if ($time >= 31556926) { $value["years"] = floor($time / 31556926); $time = ($time % 31556926); $t .= $value["years"] . "年"; } if ($time >= 86400) { $value["days"] = floor($time / 86400); $time = ($time % 86400); $t .= $value["days"] . "天"; } if ($time >= 3600) { $value["hours"] = floor($time / 3600); $time = ($time % 3600); $t .= $value["hours"] . "小时"; } if ($time >= 60) { $value["minutes"] = floor($time / 60); $time = ($time % 60); $t .= $value["minutes"] . "分"; } $value["seconds"] = floor($time); //return (array) $value; $t .= $value["seconds"] . "秒"; return $t; } else { return (bool) false; } }
推荐学习:《PHP视频教程》
以上就是php怎么将秒数转换成时分秒的详细内容,更多请关注php中文网其它相关文章!
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/php/146212.html