Various Date Formats:   Return to List

' These date formats are obtained from the addDate() function -- at bottom:

addDate()' Wed Mar 2 08:02:43 EST 2005
addDate( "MMDDYY" )' 03/02/05
addDate( "MMDDYYYY" )' 03/02/2005
addDate( "MMMDDYYYY" )' Mar 02, 2005
addDate( "MMMMDDYYYY" )' March 02, 2005
addDate( "WWWMMMDDYYYY" )' Wed, Mar 02, 2005
addDate( "WWWWMMMMDDYYYY" )' Wednesday, March 02, 2005
addDate( "MMMM" )' March
addDate( "WWWW" )' Wednesday
addDate( "HHMMSS" )' 08:02:43
addDate( "HHMM" )' 08:02

function addDate( dateformat )
{
    var curdate = "";
    var now     = new Date();
    curWDay     = now.getDay();
    curWDayShort = WDaysShort[ now.getDay() ];
    curWDayLong = WDaysLong[ now.getDay() ];
    curDate     = ( now.getDate() < 10 ) ? "0" + now.getDate() : now.getDate();
    curMonth     = now.getMonth() + 1;
    curMonth     = ( curMonth < 10 ) ? "0" + curMonth : curMonth;
    curMonthShort = MonthsShort[ now.getMonth() ];
    curMonthLong = MonthsLong[ now.getMonth() ];
    curYearLong = ( !document.all ) ? now.getYear() + 1900 : now.getYear();
    curYearShort = curYearLong.toString().substring( 2, 4 );
    curHours     = ( now.getHours() < 10 ) ? "0" + now.getHours() : now.getHours();
    curMinutes    = ( now.getMinutes() < 10 ) ? "0" + now.getMinutes() : now.getMinutes();
    curSeconds    = ( now.getSeconds() < 10 ) ? "0" + now.getSeconds() : now.getSeconds();

    switch( dateformat )
    {
        case "MMDDYY":
            curdate = curMonth + "/" + curDate + "/" + curYearShort;
            break;
        case "MMDDYYYY":
            curdate = curMonth + "/" + curDate + "/" + curYearLong;
            break;
        case "MMMDDYYYY":
            curdate = curMonthShort + " " + curDate + ", " + curYearLong;
            break;
        case "MMMMDDYYYY":
            curdate = curMonthLong + " " + curDate + ", " + curYearLong;
            break;
        case "WWWMMMDDYYYY":
            curdate = curWDayShort + ", " + curMonthShort + " " + curDate + ", " + curYearLong;
            break;
        case "WWWWMMMMDDYYYY":
            curdate = curWDayLong + ", " + curMonthLong + " " + curDate + ", " + curYearLong;
            break;
        case "MMMM":
            curdate = curMonthLong;
            break;
        case "WWWW":
            curdate = curWDayLong;
            break;
        case "HHMMSS":
            curdate = curHours + ":" + curMinutes + ":" + curSeconds;
            break;
        case "HHMM":
            curdate = curHours + ":" + curMinutes;
            break;
        default:
            curdate = now;
            break;
    }
    document.write( curdate );
}



Note to Webmaster