Home  >  Article  >  Web Front-end  >  JS small example of subtracting two dates to obtain the number of days (compatible with IE, FF)_javascript skills

JS small example of subtracting two dates to obtain the number of days (compatible with IE, FF)_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:30:411130browse
Copy code The code is as follows:

function GetDay() {
var arrDate, objDate1, objDate2, intDays;

objDate1 = new Date();
objDate2 = new Date();

arrDate = $("#StartDate").val().split("- ");
objDate1.setFullYear(arrDate[0], arrDate[1], arrDate[2]);

arrDate = $("#EndDate").val().split(" -");
objDate2.setFullYear(arrDate[0], arrDate[1], arrDate[2]);

intDays = parseInt(Math.abs(objDate1 - objDate2) / 1000 / 60 / 60 / 24);

$("#Days").val(intDays 1);
}
Statement:
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