美文网首页
小程序算两个时间的月份差 new date();

小程序算两个时间的月份差 new date();

作者: 楚昂_ing | 来源:发表于2019-08-22 18:15 被阅读0次
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));

相关文章

网友评论

      本文标题:小程序算两个时间的月份差 new date();

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