human readable millisecond timestamp


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.