// First grab some date-time variables from the Date() constructor DTnow = new Date(); // create new date object 'DTnow' Year = DTnow.getYear(); // years since 1900 (maybe! - see below) Month = DTnow.getMonth(); // month-of-year field (0-11) DayN = DTnow.getDay(); // day-of-week field (0-6) DayM = DTnow.getDate(); // day-of-month field (1-31) Hour = DTnow.getHours(); // hours field (0-23) Mins = DTnow.getMinutes(); // minutes field (0-59) Secs = DTnow.getSeconds(); // seconds field (0-59) // Tidy up, zero-pad, etc, some of the variables if (Year < 1000){ // workaround for incompatible year Year = Year + 1900; // return values in some browsers where } // getYear() returns the year *itself* if (Hour >= 12){ AmPm = "pm"; } else { AmPm = "am"; } if (Hour > 12) { Hour = Hour -12; } if (Hour == 0) { Hour = 12; } if (Hour < 10 ) { Hour = "0" + Hour; } if (Mins < 10 ) { Mins = "0" + Mins; } if (Secs < 10) { Secs = "0" + Secs; } /* Fill and pick from Name-of-Day-of-Week array (DayN=0-6) viz: DoW[0]="Sunday", DoW[3]="Wednesday", etc */ var DoW = new Array("Sunday","Monday","Tuesday", "Wednesday","Thursday","Friday","Saturday"); // DayName = DoW[DayN]; // eg: Monday <<< // comment *1* of these DayName = DoW[DayN].substring(0,3); // eg: Mon <<< /* Fill and pick from Name-of-Month array (Month=0-11) viz: Mths[0]="January", Mths[11]="December", etc */ var Mths = new Array("January","February","March", "April","May","June","July","August","September", "October","November","December"); // MthName = Mths[Month]; // eg: February <<< // comment *1* of these MthName = Mths[Month].substring(0,3); // eg: Feb <<< /* Next section is for alternative numeric DD.MM.YY format (eg: 12.02.01) */ DD = DayM; if (DD < 10) { DD = "0" + DD; // in case DD.mm.yy wanted } MM = Month + 1; if (MM < 10) { MM = "0" + MM; // in case dd.MM.yy wanted } YY = Year.toString().substr(2,2); // in case dd.mm.YY wanted /* Assemble Date-Time-Stamp variable (DTstamp) by successively concatenating on the various components. Comment (or edit) out any you don't want (eg: for date only, time only, short forms of Day, Month, numeric only, etc */ DTstamp = DayM; // eg: 12 DTstamp = DTstamp + "." + MthName; // eg: Feb/February DTstamp = DTstamp + "." + Year; // eg: 2001, // Print it! document.write(DTstamp); //document.write(DD+"."+MM+"."+YY); // eg: 12.02.01 format // End