Posted By

clapfouine on 01/24/08


Tagged

time human convert


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

adix
SpinZ


human readable millisecond timestamp


 / Published in: JavaScript
 

  1. <script>
  2.  
  3. function two(x) {return ((x>9)?"":"0")+x}
  4. function three(x) {return ((x>99)?"":"0")+((x>9)?"":"0")+x}
  5.  
  6. function time(ms) {
  7. var sec = Math.floor(ms/1000)
  8. ms = ms % 1000
  9. t = three(ms)
  10.  
  11. var min = Math.floor(sec/60)
  12. sec = sec % 60
  13. t = two(sec) + ":" + t
  14.  
  15. var hr = Math.floor(min/60)
  16. min = min % 60
  17. t = two(min) + ":" + t
  18.  
  19. var day = Math.floor(hr/60)
  20. hr = hr % 60
  21. t = two(hr) + ":" + t
  22. t = day + ":" + t
  23.  
  24. return t
  25. }
  26.  
  27. document.write(time(12034056070))
  28. </script>

Report this snippet  

You need to login to post a comment.