Get time difference and time format in jqueryjs code _ jquery-js tutorial

Source: Internet
Author: User
There are many methods to obtain time difference and time format. The following describes how to use the function code of jquery and js to retrieve

The Code is as follows:


GetDateDiff (start, end, "day ")
/*
* Time Difference obtained, in the format of year-month-day hour: minute: Second or year/month/day hour: minute: Second
* The year, month, and day are in full format, for example, 01:00:00
* Return accuracy: seconds, minutes, hours, days
*/
Function GetDateDiff (startTime, endTime, diffType ){
// Convert the time format of xxxx-xx to the format of xxxx/xx
StartTime = startTime. replace (/-/g ,"/");
EndTime = endTime. replace (/-/g ,"/");
// Converts the computing interval class characters to lowercase letters.
DiffType = diffType. toLowerCase ();
Var sTime = new Date (startTime); // start time
Var eTime = new Date (endTime); // End Time
// Number used as the Divisor
Var pNum = 1;
Switch (diffType ){
Case "second ":
Pnum= 1000;
Break;
Case "minute ":
Pnum= 1000*60;
Break;
Case "hour ":
Pnum= 1000*3600;
Break;
Case "day ":
PNum = 1000*3600*24;
Break;
Default:
Break;
}
Return parseInt (eTime. getTime ()-sTime. getTime ()/parseInt (pNum); // 17jquery.com
}

Related Article

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.