编写程序,判断并输出今天是开学的第几周,星期几(javascript编写)
发布网友
发布时间:2022-04-25 15:39
我来回答
共1个回答
热心网友
时间:2022-04-25 17:08
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
<script type="text/javascript" src="js/jquery-min.js"></script>
<style type="text/css">
</style>
</head>
<body>
<div id="start"></div>
<div id="now"></div>
<div id="nowADay"></div>
<script type="text/javascript">
(function(){
var start = document.getElementById('start');
var now = document.getElementById('now');
var nowADay = document.getElementById('nowADay');
var startDay = new Date(2013,7,26);// 2013,7,26 是开学时间,可以按格式改,月份从0开始
var startMs = startDay.getTime();
var startYear = startDay.getFullYear();
var startMonth = startDay.getMonth()+1;//月份从0开始
var startDate = startDay.getDate();
var nowDay = new Date();
var nowMs = nowDay.getTime();
var nowYear = nowDay.getFullYear();
var nowMonth = nowDay.getMonth()+1;
var nowDate = nowDay.getDate();
var startDays = parseInt(startMs/86400000);
var nowDays = parseInt(nowMs/86400000);
var totalDays = nowDays - startDays;
var week = parseInt(totalDays/7);
var nowdate = totalDays%7;
start.innerHTML = "开学时间:" + startYear + " 年 " + startMonth + " 月 " + startDate + "日";
now.innerHTML = "现在时间:" + nowYear + " 年 " + nowMonth + " 月 " + nowDate + "日";
nowADay.innerHTML = "第" + week + "周,星期" + nowdate;
})();
</script>
</body>
</html>
几分钟帮你写了一个,纯手打,天冷请采纳