Created
June 20, 2018 15:41
-
-
Save timvisee/53c71681323a2a8177506507fb224b21 to your computer and use it in GitHub Desktop.
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 duration($s) { | |
do | |
$c[] = str_pad(isset($c) && sizeof($c) > 1 ? $s : $s % 60, isset($c) && $s < 60 ? 1 : 2, 0, STR_PAD_LEFT); | |
while(($s = floor($s / 60)) > 0 && sizeof($c) < 3); | |
return implode(":", array_reverse($c)); | |
} | |
// duration(0); -> 00 | |
// duration(3); -> 03 | |
// duration(20); -> 20 | |
// duration(61); -> 1:01 | |
// duration(3601); -> 1:00:01 | |
// duration(67823430); -> 18839:50:30 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment