Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 17:30:41
Original
1148 people have browsed it
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);
}
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