计算两个日期之间的剩余天数

var aDate, oDate1, oDate2, iDays;
      var date = new Date();
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      var sDate1 = year + "-" + month + "-" + day;
      aDate = sDate1.split("-");
      oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);  //转换为yyyy-MM-dd格式
      var sDate2 = "2020-11-31";
      aDate = sDate2.split("-");
      oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);
      var  iDays = parseInt((oDate2 - oDate1) / 1000 / 60 / 60 / 24); //把相差的毫秒数转换为天数
      console.log('days',iDays)

 

    原文作者:张二狗a
    原文地址: https://blog.csdn.net/qq_41306166/article/details/113186290
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞