美文网首页
获取指定日期至另一个指定日期之间相差多少天

获取指定日期至另一个指定日期之间相差多少天

作者: 该帐号已被查封_才怪 | 来源:发表于2018-12-11 15:59 被阅读41次
    //   传参举例:  starDateString '2018-02-11'  endDataString ' 2018-12-31 '
            function getIntervalDate(starDateString, endDataString) {
              const allDifference = Date.parse(endDataString) - Date.parse(starDateString);
              const dayConvert = 1000 * 60 * 60 * 24;
              const hoursConvert = 1000 * 60 * 60;
              const minutersConvert = 1000 * 60;
              const secondsConvert = 1000;
              const dayDifference = parseInt(allDifference / dayConvert);
              const hoursDifference = parseInt((allDifference % dayConvert) / hoursConvert);
              const minutesDifference = parseInt(allDifference % dayConvert % hoursConvert / minutersConvert);
              const secondsDifference = parseInt(allDifference % dayConvert % hoursConvert % minutersConvert / secondsConvert);
              const str = `从${starDateString}距离${endDataString}还有${dayDifference}天${hoursDifference}小时${minutesDifference}分钟${secondsDifference}秒`;
              return str;
            }
    
    
    image.png

    相关文章

      网友评论

          本文标题:获取指定日期至另一个指定日期之间相差多少天

          本文链接:https://www.haomeiwen.com/subject/rykehqtx.html