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

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

2025-03-13 15:03:17 前端知识 前端哥 21 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
标签
评论
会员中心 联系我 留言建议 回顶部
浏览器升级提示:您的浏览器版本较低,建议您立即升级为知了极速浏览器,极速、安全、简约,上网速度更快!立即下载
复制成功!