Calculate the time difference between two days

Source: Internet
Author: User

<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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.