Posted By

aristoworks on 09/16/11


Tagged

time seconds hhmmss


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

frenchflair


Convert Seconds To HH:MM:SS


 / Published in: PHP
 

URL: http://www.aristoworks.com

This came in handy when I was working with Hour / Minute / Second dropdown on a page.

  1. function seconds($seconds) {
  2.  
  3. // CONVERT TO HH:MM:SS
  4. $hours = floor($seconds/3600);
  5. $remainder_1 = ($seconds % 3600);
  6. $minutes = floor($remainder_1 / 60);
  7. $seconds = ($remainder_1 % 60);
  8.  
  9. // PREP THE VALUES
  10. if(strlen($hours) == 1) {
  11. $hours = "0".$hours;
  12. }
  13.  
  14. if(strlen($minutes) == 1) {
  15. $minutes = "0".$minutes;
  16. }
  17.  
  18. if(strlen($seconds) == 1) {
  19. $seconds = "0".$seconds;
  20. }
  21.  
  22. return $hours.":".$minutes.":".$seconds;
  23.  
  24. }

Report this snippet  

You need to login to post a comment.