题目:
根据用户输入的年月日 判断该日期是星期几 ? 描述 1900/1/1是星期一
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
var year=parseInt(prompt("请输入年份:"));
var month=parseInt(prompt("请输入月份:"));
var day=parseInt(prompt("请输入日期:"));
var allDays=0;
for(let i=1900;i<year;i++){
if(i%4==0&&i%100!=0||i%400==0){
allDays=allDays+366;
}else{
allDays=allDays+365;
}
}
for(let i=1;i<month;i++){
switch(i){
case 4:
case 6:
case 9:
case 11:
allDays=allDays+30;
break;
case 2:
if(year%4==0&&year%100!=0||year%400==0){
allDays+=29;
}else{
allDays+=28;
}
break;
default:
allDays+=31;
break;
}
}
allDays+=day-1;
let result=allDays%7;
switch(result){
case 0:
document.write("星期一");
break;
case 1:
document.write("星期二");
break;
case 2:
document.write("星期三");
break;
case 3:
document.write("星期四");
break;
case 4:
document.write("星期五");
break;
case 5:
document.write("星期六");
break;
case 6:
document.write("星期日");
break;
}
</script>
</head>
<body>
</body>
</html>
方法有很多这个只供大家参考,交流学习。也希望大佬提及意见!
|