Clamas92

Standard Clock

Apr 22nd, 2013
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3. <title>JavaScript Timepiece</title>
  4. <style type="text/css">
  5. #clock
  6. {
  7. border:1px solid #e4e4f5;
  8. margin:4px;
  9. padding:3px;
  10. font-family:Tahoma, Geneva, sans-serif;
  11. font-size:12px;
  12. width:200px;
  13. }
  14. h3
  15. {
  16. font-family:Georgia, "Times New Roman", Times, serif;
  17. color:#000;
  18. }
  19. hr
  20. {
  21. color:#063;
  22. }
  23. </style>
  24.  
  25. <script type="text/javascript">
  26. function startClock() {
  27.         var today = new Date();
  28.         var h=today.getHours();
  29.         var m=today.getMinutes();
  30.         var s=today.getSeconds();
  31.        
  32.         m=checkTime(m);
  33.         s=checkTime(s);
  34.        
  35.         if(h > 12)
  36.         {
  37.                 h=h-12;
  38.                 s=s+" PM";
  39.         } else if (h==12)
  40.         {
  41.                 s=s+" PM";
  42.         }
  43.         else
  44.         {
  45.                 s=s+" AM";
  46.         }
  47.        
  48.         document.getElementById("clock").innerHTML = h + ":" + m + ":" + s;
  49.         t=setTimeout('startClock()',1000);
  50. }
  51. function checkTime(i)
  52. {
  53.         if(i<10)
  54.         {
  55.                 i="0"+i;
  56.         }
  57.         return i;
  58. }
  59.  
  60. </script>
  61. </head>
  62.  
  63. <body onLoad="startClock()">
  64. <h3>The Time ...</h3><hr />
  65. <div id="clock"></div>
  66. </body>
  67. </html>
Advertisement
Add Comment
Please, Sign In to add comment