首页 > 其他分享 >moment.js 获取国内自燃周开始时间与结束时间以及当前日期第几周

moment.js 获取国内自燃周开始时间与结束时间以及当前日期第几周

时间:2022-12-10 13:36:50浏览次数:43  
标签:monday format sunday js moment 2022 date 自燃

/**
* 国内自然周
*/
const getWeekOfNature=(date,format)=>{
let weekOfday = moment(date).format("E"); //计算是这周第几天
let monday = moment(date).subtract(weekOfday - 1, "days"); //获取周一
let sunday = moment(date).add(7 - weekOfday, "days"); // 获取周日
return {
week:moment(monday).format("WW"),
startDate: format ?monday.format(format): monday,
endDate:format ?sunday.format(format): sunday,
}
}
console.log(getWeekOfNature('2022-10-07','YYYY-MM-DD')) // {week: '40', startDate: '2022-10-03', endDate: '2022-10-09'}

 



标签:monday,format,sunday,js,moment,2022,date,自燃
From: https://blog.51cto.com/u_15469180/5927541

相关文章