new Date("2019-08-23");//2019-08-23 08:00:00
new Date("2019/08/23");//2019-08-23 00:00:00
//算两个时间的月份差
let options={
startDate:'2019-08-23',
endDate:'2019-09-24'
}
let start = new Date(options.startDate.replace(/\-/g,"/"));
let end = new Date(options.endDate.replace(/\-/g, "/"));
let startYear = start.getFullYear();
let startMonth = start.getMonth();
let endYear = end.getFullYear();
let endMonth = end.getMonth();
let monthCount = (endYear - startYear) * 12 + endMonth - startMonth;
//算两个时间天数差
let start = new Date(options.startDate.replace("-","/")).getTime();
let end = new Date(options.endDate.replace("-", "/")).getTime();
let day = Math.floor((end - start) / (1000 * 60 * 60 * 24));
网友评论