Date object initialization:
var d = new Date(); Current date and time var d = new Date(milliseconds); //from 1/1/1970 var d = new Date(datestring); //"m,d,y","1,2,2000" var d = new Date(year, month, day, hours, minutes, seconds, milliseconds); //month [0-11]
var d = new Date(); alert(d.toDateString()); //current date alert(d.getDate()); //day of the month d.setDate(24); alert(d.toDateString());
var d = new Date(); alert(d.getDay()); //week day of today
var d = new Date(); alert(d.getFullYear()); //this year d.setFullYear(2010); alert(d.toDateString()); //this day in 2010
var d = new Date(); alert(d.getHours()); //this hour d.setHours(1); alert(d.getHours()); //1:00 am today
var d = new Date(); alert(d.getMonth()); //this month d.setMonth(0); alert(d.toDateString()); //January this day
var d = new Date(); alert(d.getTime()); d.setTime(d.getTime() + 1000 * 3600 * 24 * 365); //Almost one year later alert(d.toDateString());
var d = new Date(); alert(d.toDateString());
var d = new Date(); alert(d.toISOString());
var d = new Date(); alert(d.toJSON());
var d = new Date(); alert(d.toString());
var d = new Date(); alert(d.toLocaleString());
var d = new Date(); alert(d.toLocaleDateString());
Note: ToLocaleDateString() may not work properly in Chrome browser.
var d = new Date(); alert(d.toUTCString());
var d = new Date(); alert(d.toLocaleTimeString());
Note: ToLocaleTimeString() may not accurate in Chrome browser.
var d = new Date(); alert(d.toTimeString());
var d = new Date(); alert(d.valueOf());
var d = new Date(); alert(d.getTimezoneOffset());
var ms = Date.parse("April,7,2000");//955080000000
var d = new Date(); var x = d.constructor; //x = "function Date() {[native code]}"
Date.prototype.addoneyear = function() { var yr = this.getFullYear() + 1; this.setFullYear(yr); } var d = new Date("10,8,2000"); alert(d.toDateString()); //Sun Oct 08 2000 d.addoneyear(); alert(d.toDateString()); //Mon Oct 08 2001