PHP - 115 102 bytes
A solution in 155 bytes (wrapped here on 3 lines for readability):
$a=$argv[1];
$h=($a-($m=($a=($a-($s=($a=($a-($t=($a=($a-($u=$a%1000))/1000)%1000))/1000)%60))/60)%60))/60;
printf("%02d:%02d:%02d:%03d:%03d",$h,$m,$s,$t,$u);
The second line computes (from inside to outside) the exact values of the components starting with the microseconds.
The shorter version (115 bytes, wrapped on two lines for readability):
$u=$argv[1];$h=($m=($s=($t=$u/1000)/1000)/60)/60;
printf("%02d:%02d:%02d:%03d:%03d",$h,$m%60,$s%60,$t%1000,$u%1000);
It also uses embedded assignments to compute the convert the input number of microseconds in milliseconds, seconds, minutes and hours using floating point numbers. The modulus operator (%
) and the decimal number format (%d
) of printf()
is then used to force them to integer numbers (the fractional part is ignored).
Another solution that uses the date functions (102 bytes)
$u=$argv[1];
echo gmdate("H:i:s",strtotime("@".substr($u,0,-6))),":",substr($u,-6,3),":",substr($u,-3);
The hours:minutes:seconds part is handled by the PHP date functions gmdate()
and strtotime()
, the milli- and micro-seconds are extracted as strings from the input value.
Usage:
$ php -r '$u=$argv[1];echo gmdate("H:i:s",strtotime("@".substr($u,0,-6))),":",substr($u,-6,3),":",substr($u,-3);' 7198898787; echo
01:59:58:898:787
hh:mm:ss.000000
would probably have been better (and easier). Still, can't go changing it now. \$\endgroup\$