例如: 2019 年6月1日: 星期六
2019 年6月2日: 星期天
2019 年6月3日: 星期一
……
2019 年6月30日: 星期天
// 2019,6 - > 得到这个月的天数
// new Date(2019,6-1,date).getDay()
<script>
// 求出某年某月的每一天的星期
function getEveryDay(year,m){
// 得到自定义的年月的星期数
var now = new Date(2019,6,0).getDate();
// console.log(now);
// 得到当前月份的天数
// 通过循环得到每一天的星期数
for(var i = 1;i<= now;i++){
var week = new Date(2019,5,i).getDay();
console.log(`2019年6月${i}日:星期 ${getDay(week)}`)
}
}
function getDay(day){
// 使用switch分支
switch(day){
case 0:
return '天';
case 1:
return '一';
case 2:
return '二';
case 3:
return '三';
case 4:
return '四';
case 5:
return '五';
case 6:
return '六';
}
}
getEveryDay(2019,6);
</script>