Convert seconds into days, hours, minutes and seconds

后端 未结 24 2608
说谎
说谎 2020-11-22 16:30

I would like to convert a variable $uptime which is seconds, into days, hours, minutes and seconds.

Example:



        
24条回答
  •  醉话见心
    2020-11-22 17:06

    Here it is a simple 8-lines PHP function that converts a number of seconds into a human readable string including number of months for large amounts of seconds:

    PHP function seconds2human()

    function seconds2human($ss) {
    $s = $ss%60;
    $m = floor(($ss%3600)/60);
    $h = floor(($ss%86400)/3600);
    $d = floor(($ss%2592000)/86400);
    $M = floor($ss/2592000);
    
    return "$M months, $d days, $h hours, $m minutes, $s seconds";
    }
    

提交回复
热议问题