Skip to content

Instantly share code, notes, and snippets.

@timvisee
Created June 20, 2018 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timvisee/53c71681323a2a8177506507fb224b21 to your computer and use it in GitHub Desktop.
Save timvisee/53c71681323a2a8177506507fb224b21 to your computer and use it in GitHub Desktop.
<?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