Home > Web Front-end > JS Tutorial > jquery js obtains the specific code of time difference and time format_jquery

jquery js obtains the specific code of time difference and time format_jquery

WBOY
Release: 2016-05-16 17:32:40
Original
1192 people have browsed it

Retrieve

Copy code The code is as follows:

GetDateDiff(start, end, "day")
/*
* Get the time difference, the time format is year-month-day hour:minute:second or year/month/day hour:minute:second
* Among them, year, month and day are in full format, for example : 2010-10-12 01:00:00
* The return precision is: seconds, minutes, hours, days
*/
function GetDateDiff(startTime, endTime, diffType) {
//will The time format of xxxx-xx-xx is converted to the format of xxxx/xx/xx
startTime = startTime.replace(/-/g, "/");
endTime = endTime.replace(/-/g , "/");
//Convert calculation interval characters to lowercase
diffType = diffType.toLowerCase();
var sTime = new Date(startTime); //Start time
var eTime = new Date(endTime); //End time
//Number as divisor
var divNum = 1;
switch (diffType) {
case "second":
divNum = 1000;
break;
case "minute":
divNum = 1000 * 60; break;
case "day":
divNum = 1000 * 3600 * 24;
break;
default:
break;
}
return parseInt((eTime.getTime () - sTime.getTime()) / parseInt(divNum)); //17jquery.com
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template