1. Create Date objects
Copy Code code as follows:
var now = new Date (); Get current system date and time
var somedate = new Date (Date.parse ("may 25,2012"));
var somedate = new Date ("may 25,2012"); Same as on
var somedate = new Date (DATE.UTC (2010,0)); GMT time January 1, 2010 0 o'clock in the morning
var somedate = new Date (2010,0); Same as on
var somedate = new Date (DATE.UTC (2010,4,5,17,55,55)); GMT Time May 2010 5:55:55, month and time with 0 base, 0 for month
var somedate = new Date (2010,4,5,17,55,55); Same as on
Date.parse () and DATE.UTC () return the number of milliseconds for the corresponding date, the DATE.UTC () parameters are: year, month, day, hour, minute, second, millisecond. At least 2 years and a month. The month and the time are based on 0.
2. Comparison of dates
Copy Code code as follows:
var date1 = new Date (2007,0,1);
var date2 = new Date (2007,1,1);
alert (DATE1>DATE2); False
alert (DATE1<DATE2); True
3. Date format method and get Set Date method
Copy Code code as follows:
View Code
todatestring ()
totimestring ()
toLocaleDateString () As of January 1, 2007
toLocaleTimeString ()//As 13:55:55
toUTCString ()
GetTime ()//return the number of milliseconds
SetTime ()
getFullYear ()//Get year, such as 2007
setFullYear ()
GetMonth ()//Get month, 0 for January
setmonth ()//Set month, 0 for January, more than 11 year added
GetDate ()///Get days in Date
Setdate ()//Set number of days, more than 31 added month
Getday ()//Get week, 0 for Sunday, 6 for Saturday
GetHours ()//Get hour, 0~23
sethours ()//Set hours, 0~23
getminutes ()//Get minutes, 0~59
Setminutes ()/Set minutes, 0~59
Getseconds ()//Get seconds, 0~59 setseconds ()//Set the number of seconds, 0~59
getmilliseconds ()//Get milliseconds
setmilliseconds ()//set milliseconds