Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the function of converting seconds in php

Shulou Source: shulou.com Published: 2022-06-03 17:08:58 11月05日 Update

This article mainly introduces how to use php to convert the number of seconds of the function, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

1. Convert the number of seconds into hours and seconds by the "function changeTimeType ($seconds) {...}" method.

/ * convert seconds to hours and seconds * * @ param seconds $seconds * @ return void * / function changeTimeType ($seconds) {if ($seconds > 3600) {$hours = intval ($seconds / 3600); $time = $hours. ":" Gmstrftime ('% time% slots, $seconds);} else {$time = gmstrftime ('% Hpurs% Mpurs% slots, $seconds);} return $time;}

2. Convert the number of seconds into annual days, minutes and seconds by the "function Sec2Time ($time) {...}" method.

/ * converted to annual days and seconds * * @ 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"]. Year;} if ($time > = 86400) {$value ["days"] = floor ($time / 86400); $time = ($time% 86400); $t. = $value ["days"]. "days";} if ($time > = 3600) {$value ["hours"] = floor ($time / 3600); $time = ($time% 3600); $t. = $value ["hours"]. Hours;} if ($time > = 60) {$value ["minutes"] = floor ($time / 60); $time = ($time% 60); $t. = $value ["minutes"]. "points";} $value ["seconds"] = floor ($time); / / return (array) $value; $t. = $value ["seconds"]. "seconds"; return $t;} else {return (bool) false;}} Thank you for reading this article carefully. I hope the article "how to use php to convert the number of seconds" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles functions methods time value interest minutes and seconds at the same time time hours adulthood more friends knowledge editing industry information information channels channels references Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Microsoft vpn OPPO Reno Shulou Tech Info