Advertisement
julong

update time with javascript

Aug 18th, 2014
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. <!--
  2. /////////////////////////////////////////////////////////////////////////////
  3. /////////////////////////////////////////////////////////////////////////////
  4. ///////
  5. /////// Author : EAKKASIT TUNSAKOOL
  6. ///////
  7. /////// ref : http://www.plus2net.com/javascript_tutorial/clock.php
  8. ///////
  9. /////////////////////////////////////////////////////////////////////////////
  10. -->
  11. <!DOCTYPE html>
  12. <html lang="en">
  13. <head>
  14. <meta charset="UTF-8">
  15. <title>time</title>
  16. </head>
  17. <body>
  18. <script type="text/javascript">
  19. function updateTime(){
  20. var currentTime = new Date()
  21. var hours = currentTime.getHours()
  22. var minutes = currentTime.getMinutes()
  23. var seconds = currentTime.getSeconds()
  24. if (seconds<=9){
  25. seconds="0"+seconds
  26. }
  27. if (minutes < 10){
  28. minutes = "0" + minutes
  29. }
  30. var t_str = hours + ":" + minutes + " "+":"+seconds;
  31. if(hours > 11){
  32. t_str += "PM";
  33. } else {
  34. t_str += "AM";
  35. }
  36.  
  37. document.getElementById('time_span').innerHTML = t_str;
  38. }
  39. setInterval(updateTime, 1000);
  40. </script>
  41. <div id="time_span">time</div>
  42. </body>
  43. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement