topical media & game development

talk show tell print

basic-javascript-04-ch4-examp7.htm / htm



  <html>
  <body>
  <script language="JavaScript" type="text/javascript">
  
  var greeting;
  
  var nowDate = new Date();
  var nowHour = nowDate.getHours();
  var nowMinute = nowDate.getMinutes();
  var nowSecond = nowDate.getSeconds();
  
  if (nowMinute < 10)
  {
     nowMinute = "0" + nowMinute;
  }
  
  if (nowSecond < 10)
  {
     nowSecond = "0" + nowSecond;
  }
  
  if (nowHour < 12)
  {
     greeting = "Good Morning";
  }
  else if (nowHour < 17)
  {
     greeting = "Good Afternoon";
  }
  else
  {
     greeting = "Good Evening";
  }
     
  document.write("<h4>" + greeting + " and welcome to my website</h4>")
  document.write("According to your clock the time is ");
  document.write(nowHour + ":" + nowMinute + ":" + nowSecond);
  
  </script>
  </body>
  </html>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.