home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2004 March / PCWMAR04.iso / javascript / date.js < prev    next >
Text File  |  2003-07-28  |  1KB  |  37 lines

  1. if (typeof(addtime) == "undefined")
  2.     var addtime = true;
  3. days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
  4. months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
  5.  
  6. function renderDate(){
  7.     var mydate = new Date();
  8.     var year;
  9.     if (mydate.getFullYear)
  10.         year = mydate.getFullYear();
  11.     else {
  12.         year = mydate.getYear();
  13.         if (year < 100)
  14.             year = parseInt(2000 + year);
  15.         else
  16.             year = parseInt(1900 + year);
  17.     }
  18.     var day = mydate.getDay();
  19.     var month = mydate.getMonth();
  20.     var daym = mydate.getDate();
  21.     if (daym < 10)
  22.         daym = "0" + daym;
  23.     var hours = mydate.getHours();
  24.     var minutes = mydate.getMinutes();
  25.     var dn = "AM";
  26.     if (hours >= 12) {
  27.         dn = "PM";
  28.         hours = hours - 12;
  29.     }
  30.     if (hours == 0)
  31.         hours = 12;
  32.     if (minutes <= 9)
  33.         minutes = "0" + minutes;
  34.     document.writeln(" ",days[day]," ",daym," ",months[month]," ",year,(addtime?" | "+hours+":"+minutes+" "+dn:""));
  35. }
  36. renderDate();
  37.