Date.prototype.format = function (format) {
var o = {
"m+": This.getmonth () + 1,//month
"D+": This.getdate (),//day
"H +": this.gethours (),//hour
"m+": This.getminutes (),//minute
"S+": This.getseconds (),//second
"q+": Math.floor ((This.getmonth () + 3)/3),//quarter
"S": This.getmilliseconds ()//millisecond
}
if (/(y+)/.test (format)) format = Format.replace (regexp.$1,
(This.getfullyear () + ""). substr (4-regexp.$1.length));
For (var k in O) if (New RegExp ("(" + K + ")"). Test (format))
Format = Format.replace (regexp.$1,
Regexp.$1.length = = 1? O[K]:
("XX" + o[k]). substr (("" + o[k]). length);
return format;
}
Initialize Date load function initdate () {Currdt = new date (); showdate.innerhtml = Currdt.tolocaledatestring ();//display date var DW = Currd T.getday ();//Returns a day of the week from a Date object (0~6) var tddt;//date//day of the week in the table var OBJTB = document.getElementById ("MyTable");// Get Table object for (Var i=0;i<7;i++) {TDDT = GetDays () [I];if (tddt.tolocaledatestring () = = Currdt.tolocaledatestring ()) { Objtb.rows[0].cells[i].style.color = "Red";//currdt highlight} DW = Tddt.getday ();//day of the Week objtb.rows[0].cells[i].innerhtml = Tddt.getmonth () +1 + "Month" + tddt.getdate () + "Day Week" + aryday[dw];//Display}//re-assignment Lastday = GetDays () [6];//last day of the week FirstDay = Get Days () [0];//the first day of the week}//gets the current date one day of the week function Getweek (i) {var now = new Date (), var n = now.getday (); var start = new Date (); St Art.setdate (Now.getdate ()-n + i);//Get the first day of the week, the second day, the third day ... return start; Gets the current date within the week of the seven-day function getDays () {var days = new Array (), for (Var i=1;i<=7;i++) {Days[i-1] = Getweek (i);} return days;} Number of dates for the next week (seven days) function Getnextweekdatas (NDT) {var day = new Array (); for (Var i=1;i<=7;i++){var dt = new Date (NDT);d ays[i-1] = Getnextweek (dt,i);} return days;} The next week of the specified date (after seven days) function Getnextweek (dt,i) {var today = Dt;today.setdate (Today.getdate () +i); return today;} Gets the date of the previous week (seven days) function Getpreviousweekdatas (NDT) {var day = new Array (); for (Var i=-7;i<=-1;i++) {var dt = new Date (n DT);d Ays[7+i] = Getpreviousweek (dt,i);} return days;} Last week of the specified date (first seven days) function Getpreviousweek (dt,i) {var today = Dt;today.setdate (Today.getdate () +i); return today;} Next week function Nextweek () {setcurrdtafter ();//reset Time showdate.innerhtml = currdt.tolocaledatestring ();//Display Date// Displays the date of the week in the table var OBJTB = document.getElementById ("MyTable");//Get Table object var DW = Currdt.getday ();//Return one day of the week from a Date object (0~6) var tddt;//date for (Var i=0;i<7;i++) {TDDT = Getnextweekdatas (Lastday) [I];if (tddt.tolocaledatestring () = = Currdt.tolocaledatestring ()) {Objtb.rows[0].cells[i].style.color = "red";//currdt highlight} DW = Tddt.getday ();//day of the week ObjTB . rows[0].cells[i].innerhtml = Tddt.getmonth () +1 + "Month" + tddt.getdate () + "Day Week" + ARYDAY[DW];Show}//re-assign FirstDay = Getnextweekdatas (lastday) [0];//Note the order of assignment 1lastDay = Getnextweekdatas (lastday) [6];//Note the order of assignment 2}// Last week function Previousweek () {settcurrdtbefore (); showdate.innerhtml = Currdt.tolocaledatestring ();//Display Date// Displays the date of the week in the table var OBJTB = document.getElementById ("MyTable");//Get Table object var DW = Currdt.getday ();//Return one day of the week from a Date object (0~6) var tddt;//date for (Var i=0;i<7;i++) {TDDT = Getpreviousweekdatas (FirstDay) [I];if (tddt.tolocaledatestring () = = Currdt.tolocaledatestring ()) {Objtb.rows[0].cells[i].style.color = "red";//currdt highlight} DW = Tddt.getday ();//day of the week ObjTB . rows[0].cells[i].innerhtml = Tddt.getmonth () +1 + "Month" + tddt.getdate () + "Day Week" + aryday[dw];//Display}//re-assignment Lastday = Getpre Viousweekdatas (firstday) [6];//Note Assignment Order 1firstDay = Getpreviousweekdatas (firstday) [0];//Note Assignment order 2}//Seventh day after current date function Setcurrdtafter () {currdt.setdate (Currdt.getdate () +7);} Seventh day before the current date function Settcurrdtbefore () {currdt.setdate (Currdt.getdate ()-7);} </script> JS Display last week