Get the App
SLTechnology News&Howtos  ›  Development  › 

How to convert seconds into hours and seconds by php

Shulou Source: shulou.com Published: 2022-06-03 19:49:40 10月02日 Update

This article mainly introduces how php converts the number of seconds into hours and seconds, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let's take a look at it.

Php converts the number of seconds into hours and seconds: 1, through the "function changeTimeType ($seconds) {...}" method to convert the number of seconds into hours and seconds; 2, through the "function Sec2Time ($time) {...}" method to convert the number of seconds into annual days and seconds.

Operating environment of this article: Windows7 system, PHP7.1 version, Dell G3 computer

How does php convert seconds into hours and seconds?

PHP converts seconds to hours, minutes and seconds

One:

/ * 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;}

Two:

/ * 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 "php how to convert seconds into hours and seconds" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Time article method value interest minute and second at the same time time hour adult more friends version environment computer knowledge system editing industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Microsoft Redmi Shulou Tech Info Apple