传入的值必须为类型必须有分隔符 :-
调用
md(){ let ymd =2021-02-21 this.getWeek(ymd ) //调用
console.log(this.getWeek(ymd )) //打印
}
getWeek(ymd) { //把日期转为周几文字 // console.log(dateString) var dateArray = ymd.split("-"); // console.log(dateArray) let date = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2]); return "周"+"日一二三四五六".charAt(date.getDay());
//或者字数 },
getWeek(ymd) { //把日期转为周几数字 // console.log(dateString) var dateArray = ymd.split("-"); // console.log(dateArray) let date = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2]); return "123456".charAt(date.getDay()); //或者字数 },