首页 > 代码库 > 课程表上一周下一周
课程表上一周下一周
var currDT;var aryDay = new Array("日", "一", "二", "三", "四", "五", "六");//初始页面 function initWeek() { currDT = new Date(); showDate();}//上一周 或 下一周 function addWeek(ope) { var num = 0; if (ope == "-") { num = -7; } else if (ope == "+") { num = 7; } currDT = addDate(currDT, num); //showDate(); return currDT;}function showDate() { //span1.innerHTML = currDT.toLocaleDateString(); //显示日期 var dw = currDT.getDay(); var tdDT; //确定周一是那天 if (dw == 0) { tdDT = addDate(currDT, -6); } else { tdDT = addDate(currDT, (1 - dw)); } //在表格中显示一周的日期 var objTB = document.getElementById("trWeek"); for (var i = 0; i < 7; i++) { if (tdDT.toLocaleDateString() == currDT.toLocaleDateString()) { objTB.cells[i + 1].style.color = "red"; //currDT突出显示 } dw = tdDT.getDay(); objTB.cells[i + 1].innerHTML = "星期" + aryDay[dw] + "<br />[" + tdDT.getFullYear() + "-" + (tdDT.getMonth() + 1) + "-" + tdDT.getDate() + "]"; tdDT = addDate(tdDT, 1); //下一天 }}//增加或减少若干天,由 num 的正负决定,正为加,负为减 function addDate(dt, num) { var ope = "+"; if (num < 0) { ope = "-"; } var reDT = dt; for (var i = 0; i < Math.abs(num) ; i++) { reDT = addOneDay(reDT, ope); } return reDT;}//增加或减少一天,由ope决定, + 为加,- 为减,否则不动 function addOneDay(dt, ope) { var num = 0; if (ope == "-") { num = -1; } else if (ope == "+") { num = 1; } var y = dt.getFullYear(); var m = dt.getMonth(); var lastDay = getLastDay(y, m); var d = dt.getDate(); d += num; if (d < 1) { m--; if (m < 0) { y--; m = 11; } d = getLastDay(y, m); } else if (d > lastDay) { m++; if (m > 11) { y++; m = 0; } d = 1; } var reDT = new Date(); reDT.setYear(y); reDT.setMonth(m); reDT.setDate(d); return reDT;}//是否为闰年 function isLeapYear(y) { var isLeap = false; if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) { isLeap = true; } return isLeap;}//每月最后一天 function getLastDay(y, m) { var lastDay = 28; m++; if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) { lastDay = 31; } else if (m == 4 || m == 6 || m == 9 || m == 11) { lastDay = 30; } else if (isLeapYear(y) == true) { lastDay = 29; } return lastDay;}//获取任意周的开始时间function getAnyWeekStart(date) { var currentDay = date.getDay(); if (currentDay == 0) { currentDay = 7; } var mondayTime = date.getTime() - (currentDay - 1) * 24 * 60 * 60 * 1000; var startTime = new Date(mondayTime).toLocaleDateString(); return startTime; }//获取任意周的结束时间function getAnyWeekEnd(date) { var currentDay = date.getDay(); if (currentDay == 0) { currentDay = 7; } var sundayTime = date.getTime() + (7 - currentDay) * 24 * 60 * 60 * 1000; var endTime = new Date(sundayTime).toLocaleDateString(); return endTime;}
课程表上一周下一周
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。