PHP convert seconds to days, hours and minutes

PHP中文网
Release: 2023-02-28 19:56:01
Original
7201 people have browsed it

PHP converts seconds to days, hours and minutes:

function secsToStr($secs) {
    if($secs>=86400){$days=floor($secs/86400);
    $secs=$secs%86400;
    $r=$days.' day';
    if($days<>1){$r.=&#39;s&#39;;}
    if($secs>0){$r.=&#39;, &#39;;}}
    if($secs>=3600){$hours=floor($secs/3600);
    $secs=$secs%3600;
    $r.=$hours.&#39; hour&#39;;
    if($hours<>1){$r.=&#39;s&#39;;}
    if($secs>0){$r.=&#39;, &#39;;}}
    if($secs>=60){$minutes=floor($secs/60);
    $secs=$secs%60;
    $r.=$minutes.&#39; minute&#39;;
    if($minutes<>1){$r.=&#39;s&#39;;}
    if($secs>0){$r.=&#39;, &#39;;}}
    $r.=$secs.&#39; second&#39;;
    if($secs<>1){$r.=&#39;s&#39;;
    }
    return $r;
}
Copy after login

Usage:

<?php
$seconds = "56789";
$output = secsToStr($seconds);
echo $output;
?>
Copy after login

The above is the content of PHP to convert seconds to days, hours and minutes. For more related content, please pay attention to php Chinese website
Related tools: Unix timestamp conversion tool http://www.php.cn/xiazai/tool/5

Related articles:

Time conversion in js - sample code for converting milliseconds to date and time

PHP Convert seconds to days, hours and minutes format time

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!