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

2018-12-11  本文已影响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
上一篇下一篇

猜你喜欢

热点阅读