1. Get the current time
1 function getnowtime (){
2 return new date ();
3}
2. Add time and days
1 function gettimeadddays (time, days ){
2 return new date (time. gettime () + days * 24*60*60*1000 );
3}
3. Get and format the date: year-month-day
1 function getformatdate (time ){
2 return time. getfullyear () + "-" + (time. getmonth () + 1) + "-" + time. getdate ();
3}
4. Convert string to date. string format: 2011-11-20
Function converttodate (strings ){
Return new date (date. parse (strings. Replace ("-","/")));
}
5. Get and format the week
1 var weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; // week
2
3 function getformatweek (time ){
4 return weekdays [time. getday ()];
5}
6. Time Comparison
1 function comparetime (time1, time2 ){
2 Return time1.gettime ()-time2.gettime ();
3}
7. Calculate the number of days between two dates
Function getdays (time1, tiem2 ){
VaR day = 24*60*60*1000;
Return (time1.gettime ()-time2.gettime ()/day;
}