antonvrg

Javascript Clock

Aug 26th, 2011
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.30 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4.     <title>Javascript Clock</title>
  5.     <script type="text/javascript">
  6.         function startTimer()
  7.         {
  8.             var today=new Date();
  9.             var h=today.getHours();
  10.             var m=today.getMinutes();
  11.             var s=today.getSeconds();
  12.             var timeOfDay = ( h < 12 ) ? "AM" : "PM";
  13.             h = ( h > 12 ) ? h - 12 : h;
  14.             m=checkclock(m);
  15.             s=checkclock(s);
  16.             document.getElementById('clock').innerHTML=h+":"+m+":"+s;
  17.             document.getElementById('info').innerHTML=timeOfDay;
  18.             t=setTimeout('startTimer()',500);
  19.         }
  20.        
  21.         function checkclock(i)
  22.             {
  23.                 if (i<10)
  24.             {
  25.                 i="0" + i;
  26.             }
  27.             return i;
  28.         }
  29.     </script>
  30.     <style type="text/css">
  31.         body {background-color: #242424;}
  32.         #clock {
  33.             color: #EFEFEF;
  34.             font-family: sans, Impact, Arial, monospace;
  35.             font-size: 200px;
  36.             text-align: center;
  37.         }
  38.         #info {
  39.             color: #EFEFEF;
  40.             font-family: sans, Impact, Arial, monospace;
  41.             font-size: 50px;
  42.             text-align: center;
  43.             margin-left: 1000px;
  44.             margin-top: -95px;
  45.         }
  46.         p {
  47.             color: #EFEFEF;
  48.             font-family: sans, Impact, Arial, monospace;
  49.             font-size: 24px;
  50.             margin-right: 620px;
  51.             text-align: center;
  52.             margin-top: 200px;
  53.         }
  54.     </style>
  55. </head>
  56. <body onload="startTimer()">
  57.     <p>The Current Time Is:</p><div id="clock"></div><div id="info"></div>
  58. </body>
  59. </html>
Advertisement
Add Comment
Please, Sign In to add comment