fork(1) download
  1. <?php
  2. $dec = 0.625;
  3.  
  4. $hours = $dec * 24;
  5.  
  6. function convertTime($dec)
  7. {
  8. // start by converting to seconds
  9. $seconds = ($dec * 3600);
  10. // we're given hours, so let's get those the easy way
  11. $hours = floor($dec);
  12. // since we've "calculated" hours, let's remove them from the seconds variable
  13. $seconds -= $hours * 3600;
  14. // calculate minutes left
  15. $minutes = floor($seconds / 60);
  16. // remove those from seconds as well
  17. $seconds -= $minutes * 60;
  18. // return the time formatted HH:MM:SS
  19. return lz($hours).":".lz($minutes).":".lz($seconds);
  20. }
  21.  
  22. // lz = leading zero
  23. function lz($num)
  24. {
  25. return (strlen($num) < 2) ? "0{$num}" : $num;
  26. }
  27.  
  28. echo convertTime($hours);
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
15:00:00