Created
February 20, 2011 22:51
-
-
Save joshhartman/836400 to your computer and use it in GitHub Desktop.
Convert a Number of Seconds to a Text String of Days, Hours, Minutes, and Seconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
date_default_timezone_set('America/Chicago'); | |
function secsToStr($secs) { | |
if($secs>=86400){$days=floor($secs/86400);$secs=$secs%86400;$r=$days.' day';if($days<>1){$r.='s';}if($secs>0){$r.=', ';}} | |
if($secs>=3600){$hours=floor($secs/3600);$secs=$secs%3600;$r.=$hours.' hour';if($hours<>1){$r.='s';}if($secs>0){$r.=', ';}} | |
if($secs>=60){$minutes=floor($secs/60);$secs=$secs%60;$r.=$minutes.' minute';if($minutes<>1){$r.='s';}if($secs>0){$r.=', ';}} | |
$r.=$secs.' second';if($secs<>1){$r.='s';} | |
return $r; | |
} | |
echo secsToStr(time()-strtotime('1/1/2011')); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment