一、
function getDayOfWeek(date) {
var str = "";
var week = new Date(date).getDay();
if (week == 0) {
str = "星期日";
} else if (week == 1) {
str = "星期一";
} else if (week == 2) {
str = "星期二";
} else if (week == 3) {
str = "星期三";
} else if (week == 4) {
str = "星期四";
} else if (week == 5) {
str = "星期五";
} else if (week == 6) {
str = "星期六";
}
return str;
}
getDayOfWeek('2020-9-2'); // 星期三
二、
function getDayOfWeek(date) {
var arr = new Array("日", "一", "二", "三", "四", "五", "六");
var week = new Date(date).getDay();
var str = "星期" + arr[week];
return str;
}
getDayOfWeek('2020-9-2'); // 星期三
三、
function getDayOfWeek(date) {
var str = "星期" + "日一二三四五六".charAt(new Date(date).getDay());
return str;
}
getDayOfWeek('2020-9-2'); // 星期三
网友评论