- getDate() : Returns the date
- getMonth(): Returns the month
- getFullYear(): Returns the year
#1: month/date/year (5/12/2010)
var date = new Date();
var sysDate = date.getDate();
var sysMonth = date.getMonth();
var sysYear = date.getFullYear();
document.write(sysMonth + "/" + sysDate + "/" + sysYear);
#2: date-month-year (12-May-2010)
var date = new Date();
var sysDate = date.getDate();
var sysMonth = date.getMonth();
var sysYear = date.getFullYear();
var monthNames = new Array("January", "February", "March",
"April", "May", "June", "July", "August",
"September", "October", "November",
"December");
document.write(sysDate + "-" + monthNames[sysMonth] + "-" + sysYear);
#3: date-month-year (12th May 2010)
var date = new Date();
var sysDate = date.getDate();
var sysMonth = date.getMonth();
var sysYear = date.getFullYear();
var monthNames = new Array("January", "February", "March",
"April", "May", "June", "July", "August",
"September", "October", "November",
"December");
var sup = "";
if(sysDate == 1 || sysDate == 21 || sysDate == 31) sup ="st";
else if (sysDate == 2 || sysDate == 22) sup = "nd";
else if (sysDate == 3 || sysDate == 23) sup = "rd";
else sup = "th";
document.write(sysDate + "" + sup + " " + monthNames[sysMonth] + " " + sysYear);
No comments:
Post a Comment