// 传参举例: 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
网友评论