<script type= "Text/javascript" >/* * Get time difference in the format of year-month-day hours: minutes: seconds or Year/month/day hour: minutes: seconds * in which, month and day are in full format, for example: 2010-10-12 01:00:00 * Return accuracy: seconds, minutes, hours, days */function Getdatediff (StartTime, EndTime, Difftype) {//XXXX-XX-XX time format, convert to XXXX/XX/XX format Startt IME = Starttime.replace (/\-/g, "/"); EndTime = Endtime.replace (/\-/g, "/"); Converts the computed interval class character to lowercase difftype = difftype.tolowercase (); var stime = new Date (startTime); Start time var etime = new Date (endTime); The end time//As the number of the divisor var divnum = 1; Switch (difftype) {case "second": Divnum = 1000; Break Case "Minute": divnum = 1000 * 60; Break Case "Hour": divnum = 1000 * 3600; Break Case ' Day ': divnum = 1000 * 3600 * 24; Break Default:break; } return parseint ((Etime.gettime ()-stime.gettime ())/parseint (Divnum));} var testdate = new Date (), var teststr = Testdate.format ("Yyyy-mm-dd hh:mm:ssvar result = Getdatediff ("2010-02-26 16:00:00", Teststr, "Day");d Ocument.write ("The difference between the two is:" + result + "days.) ");</script>
The method used is simple, such as calculating the number of days to do this:
Getdatediff ("2010-02-26 16:00:00", "2011-07-02 21:48:40", "Day");
The number of seconds can be calculated as follows:
Getdatediff ("2010-02-26 16:00:00", "2011-07-02 21:48:40", "second");
Calculate the time difference between two days