JS Gets the date when it encounters the following requirements, and gets the day of the week based on the week of the year. If the start date is from Thursday to the next week Friday is one week.
Formatted Date:
functiongetnowformatdate (thedate) {varDay =thedate;varYear = 0; varMonth = 0; varDay = 0; varcurrentdate = ""; //Initialization TimeYear= day.getfullyear ();//ie Firefox can beMonth= Day.getmonth () +1; Day=day.getdate (); currentdate+ = year + "-"; if(Month >= 10) {currentdate+ = Month + "-"; } Else{currentdate+ = "0" + Month + "-"; } if(Day >= 10) {currentdate+=Day ;} Else{currentdate+ = "0" +Day ;} returncurrentdate;}
Get Date Range Display
functionvar var if null null | | _week = = "return "= getxdate (_year,_week,4= Getxdate (_year, (_week-0 + 1), 5return getnowformatdate (begindate) + "to" + getnowformatdate (endDate);}
This method will get the day of the Week (WeekDay) of the first week (weeks) of the year
functiongetxdate (year,weeks,weekday) {//constructs a Date object with the specified year and sets the date to January 1 of the year//because the month in the computer starts with 0, the following construction methods arevarDate =NewDate (year, "0", "1"); //gets the long shaping time of this date object datevarTime =Date.gettime (); //Add This long shaping time to the nth week time offset//because the first week is the current week, so there are: weeks-1, etc.//7*24*3600000 is the time of the week in milliseconds, (the date in JS is accurate to milliseconds)time+= (weeks-1) *7*24*3600000; //Reset the Date object date to timeDate.settime (time);returngetnextdate (date,weekday);}
This method will get the date of the week (WeekDay) of the week in which a date (nowdate) is located.
function//weekday%=7var day =var time = var sub = weekday-if(sub <= 0+ = 7;}time +=sub*24*3600000 return nowdate;}
JS Gets the date of the current specified previous days
1 functiongetbeforedate (n) {2 varn =N;3 varD =NewDate ();4 varYear =d.getfullyear ();5 varMon=d.getmonth (+1);6 varday=d.getdate ();7 if(Day <=N) {8 if(mon>1) {9Mon=mon-1;Ten } One Else { AYear = Year-1; -Mon = 12; - } the } -D.setdate (D.getdate ()-n); -Year =d.getfullyear (); -Mon=d.getmonth (+1); +day=d.getdate (); -s = year+ "-" + (mon<10? (' 0 ' +mon): Mon) + "-" + (day<10? (' 0 ' +Day ):d ay); + returns; A } atConsole.log (Getbeforedate (1));//Yesterday's date -Console.log (Getbeforedate (7));//date of first seven days
JS Date Calculation and quick get week, month, quarter start and end days, get a small example of a specified date week and day of the week