Home  >  Article  >  Web Front-end  >  JS 两日期相减,获得天数的小例子(兼容IE,FF)_javascript技巧

JS 两日期相减,获得天数的小例子(兼容IE,FF)_javascript技巧

WBOY
WBOYOriginal
2016-05-16 17:30:411097browse
复制代码 代码如下:

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

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

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

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

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

    $("#天数").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