首页 前端知识 Vue----计算两个日期相差的周期月份、天数

Vue----计算两个日期相差的周期月份、天数

2025-03-13 15:03:17 前端知识 前端哥 19 415 我要收藏

 1、获取两个日期的周期数

getCycle(startTime,endTime){//获取周期
  const start = new Date(startTime);
  const end = new Date(endTime);
  let years = end.getFullYear() - start.getFullYear();
  let months = end.getMonth() - start.getMonth();
  return years * 12 + months;
},

2、获取两个日期的差值 

//计算间隔天数
const start = new Date(this.startTime);
const end = new Date(this.endTime);
let dayNumber=Math.ceil((end - start) / (1000 * 60 * 60 * 24));
转载请注明出处或者链接地址:https://www.qianduange.cn//article/23535.html
标签
评论
会员中心 联系我 留言建议 回顶部
复制成功!