1、第一步先安装插件 npm install date-fns --save
2、界面引用
import { format,getWeek} from 'date-fns';
getISOWeek(w:any, y = new Date().getFullYear()) {
let d = new Date(y, 0, 4);
d.setDate(d.getDate() - (d.getDay() || 7) + 1 + 7*(w - 1));
return format(d,'yyyy-MM-dd');
}
onLoad(){
let week = getWeek(new Date())
console.log('当期第几周:'+week)
let str = (this.getISOWeek(week).toString())
console.log('本周星期一的日期',str)
}