js-判断当前日期的天数

时间:2021-09-11 13:54:52
<!DOCTYPE html>
<html>


<head>
<meta charset="utf-8" />
<title></title>
</head>


<body>
<script>
var y, m, d;
var r = 0;
var arr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
y = Number(prompt("请输入年"));
m = Number(prompt("请输入月"));
d = Number(prompt("请输入日"));
for(var i = 0; i < m - 1; i++) {
r= r+ arr[i];
}
if((y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) && m > 2) {
r= r + d + 1
document.write("该日期为"+y+"年中的第" + r + "天");
} else {
r = r + d
document.write("该日期为"+y+"年中的第" + r+ "天");
}
</script>
</body>


</html>