Created
July 11, 2012 14:24
-
-
Save agarzon/3090691 to your computer and use it in GitHub Desktop.
Calculate remaining days, hours, minutes and seconds from 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 | |
function secondsToTime($seconds) { | |
// Extract days | |
$days = floor($seconds / 86400); | |
// Extract hours | |
$divisorHours = $seconds % 86400; | |
$hours = floor($divisorHours / 3600); | |
// Extract minutes | |
$divisorMinutes = $seconds % 3600; | |
$minutes = floor($divisorMinutes / 60); | |
// Extract the remaining seconds | |
$divisorSeconds = $divisorMinutes % 60; | |
$seconds = floor($divisorSeconds); | |
$timeleft = array( | |
"d" => (int) $days, | |
"h" => (int) $hours, | |
"m" => (int) $minutes, | |
"s" => (int) $seconds, | |
); | |
return $timeleft; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment