Site hosted by Angelfire.com: Build your free website today!

 

Current Time & Date:

The Source
------------------------------------------------------------------

<SCRIPT language="JavaScript">
<!--

function startclock()
 {
 <!-- Getting the Date -->
 
  var thetime=new Date();

  var nhours=thetime.getHours();
  var nmins=thetime.getMinutes();
  var nsecn=thetime.getSeconds();
  var nday=thetime.getDay();
  var nmonth=thetime.getMonth();
  var ntoday=thetime.getDate();
  var nyear=thetime.getYear();
  var AorP=" ";

 <!--AM or PM -->

  if (nhours>=12)
      AorP="P.M.";
  else
      AorP="A.M.";

 <!-- Current Hour not in Military Time -->

  if (nhours>=13)
      nhours-=12;

  if (nsecn<10)
   nsecn="0"+nsecn;

  if (nmins<10)
    nmins="0"+nmins;

 <!-- Day as in Monday, Tuesday, etc -->
 
  if (nday==0)
     nday="Sunday";
  
  if (nday==1)
    nday="Monday";
  
  if (nday==2)
     nday="Tuesday";
  
  if (nday==3)
     nday="Wednesday";
  
  if (nday==4)
     nday="Thursday";
  
  if (nday==5)
     nday="Friday";
  
  if (nday==6)
     nday="Saturday";

 nmonth+=1;
  
  <!-- Setting the Year -->

  if ((nyear>99) && (nyear<2000))
    nyear+=1900;

 <!-- The Final Output for the Broswer

(In this case a Form) -->
 
document.clockform.clockspot.value=
nhours+": "+nmins+": "+nsecn+" "+AorP+" "+nday+",
"+nmonth+"/"+ntoday+"/"+nyear; setTimeout('startclock()',1000); } //-->
</SCRIPT>

-------------------------------------------------------------------- 

Explanation:

Well it's pretty much the same as the other one, but now I added a couple of new functions, to display the actual date and current time.

The variable nyear gives the number of years into the current century- the last two numbers of the year such as 98 or 99. One problem- the dreaded Y2K problem. In IE5+, the date actually goes to 4 numbers, to 2000. In NS 4.6 the date flips to 100- not zero! I tested the code below, and it works for these two browsers, though I did not check it with older versions- but those may have other Y2K bugs to worry about. So, if the year comes back as 99, I added a 19 in front. If it is between 99 and 2000, I added 1900 to it (100+1900=2000) so NS would work with it. IE just gives back 2000 so if it is more than 2000 it can be left alone.

if (nyear<=99)
  nyear= "19"+nyear;

if ((nyear>99) && (nyear<2000))
 nyear+=1900;

Well that's about it.