Guest User

time / greeter

a guest
Sep 19th, 2015
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.34 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title> Time </title>
  5.     <script type="text/javascript" charset="utf-8">
  6.     window.onload=init;
  7.     function init(){
  8.         startTime();
  9.  
  10.     }
  11.     function startTime() {
  12.         var greeting;
  13.         var today=new Date();
  14.         var h=today.getHours();
  15.         var m=today.getMinutes();
  16.         var s=today.getSeconds();
  17.         m = checkTime(m);
  18.         s = checkTime(s);
  19.         if (h <= 12) {
  20.             adj = 'am';
  21.             h2 = h;
  22.             greeting = "morning";
  23.         }else{
  24.             adj = 'pm';
  25.             h2=h-12;
  26.             if (h < 17) {
  27.             greeting = "afternoon"
  28.             }else{
  29.             greeting = "evening"
  30.             };
  31.         };
  32.         document.getElementById('clock').innerHTML = h2+":"+m+":"+s+" "+ adj;   // Remove   '":"+s+'    if you dont want the seconds
  33.         document.getElementById('clock24').innerHTML = h+":"+m+":"+s;       // Remove   '":"+s+'    if you dont want the seconds
  34.         document.getElementById('greeting').innerHTML = greeting;
  35.         var t = setTimeout(function(){startTime()},500);
  36.        
  37.     };
  38.     function checkTime(i) {
  39.         if (i<10) {i = "0" + i};  // add zero in front of numbers < 10
  40.         return i;
  41.     };
  42.     </script>
  43. </head>
  44. <body>
  45.     <!--  12 hr clock--><div id="clock"></div>
  46.     <!--  24 hr clock--><div id="clock24"></div>
  47.     <!--  Greeting based on time of the day--><p>Good <span id="greeting"></span>, Anon</p>
  48. </body>
  49. </html>
Advertisement
Add Comment
Please, Sign In to add comment