# Obtain the date range of the week based on the time range of the week.

Source: Internet
Author: User

Obtain the date range of the week based on the time range of the week.
Obtain the date range of the week according to the week

`/*** Return the range of Weekly Times of a month in a certain year * @ param weeks Weekly Times * @ return the range of dates of the week */function getXDate (year, weeks) {var date = new Date (year, "0", "1"); var time = date. getTime (); // get the current day of the week, 0: Monday .... Var _ week = date. getDay (); // if the first day of the year is Sunday, the current year has 54 weeks. Otherwise, if (_ week! = 0) {// 53 weeks of a year if (weeks = 54) {return 'no 54 weeks of this year';} var cnt = 0; // obtain the number of days from the weekend if (_ week = 0) {cnt = 7;} else if (_ week = 1) {cnt = 6 ;} else if (_ week = 2) {cnt = 5;} else if (_ week = 3) {cnt = 4;} else if (_ week = 4) {cnt = 3;} else if (_ week = 5) {cnt = 2;} else if (_ week = 6) {cnt = 1 ;} cnt + = 1; // Add 1 to indicate the first day of the week on Monday. // Add the long integer time to the time Offset of week N. time + = cnt * 24*3600000; // week 1 Start Time var nextYear = new Date (parseInt (year, 10) + 1, "0", "1"); var nextWeek = nextYear. getDay (); var lastcnt = 0; // obtain the number of days from the last week's start time to the weekend if (nextWeek = 0) {lastcnt = 6 ;} else if (nextWeek = 1) {lastcnt = 0;} else if (nextWeek = 2) {lastcnt = 1;} else if (nextWeek = 3) {lastcnt = 2;} else if (nextWeek = 4) {lastcnt = 3;} else if (nextWeek = 5) {lastcnt = 4 ;} else if (nextWeek = 6) {lastcnt = 5;} if (weeks = 1) {// special processing for week 1st // reset the date object to time var start = date. format ("MM dd, yyyy"); date. setTime (time-24*3600000); return start + '--' + date. format ("yyyy MM dd");} else if (weeks = 53) {// 53rd special weekly processing var start = time + (weeks-2) * 7*24*3600000; // the start time of week 53rd var end = time + (weeks-2) * 7*24*3600000 + lastcnt * 24*3600000-24*3600000; // end time of week 53rd // reset the date object to time date. setTime (start); var _ start = date. format ("MM dd, yyyy"); date. setTime (end); var _ end = date. format ("MM dd, yyyy"); return _ start + '--' + _ end;} else {var start = time + (weeks-2) * 7*24*3600000; // the nth week start time var end = time + (weeks-1) * 7*24*3600000-24*3600000; // end time of week n // reset the date object to time date. setTime (start); var _ start = date. format ("MM dd, yyyy"); date. setTime (end); var _ end = date. format ("MM dd, yyyy"); return _ start + '--' + _ end ;}} else {// var cnt = 0 for 54 weeks a year; // obtain the number of days from the weekend if (_ week = 0 & weeks = 1) {// The first week cnt = 0;} else if (_ week = 0) {cnt = 7;} else if (_ week = 1) {cnt = 6;} else if (_ week = 2) {cnt = 5 ;} else if (_ week = 3) {cnt = 4;} else if (_ week = 4) {cnt = 3;} else if (_ week = 5) {cnt = 2;} else if (_ week = 6) {cnt = 1;} cnt + = 1; // Add 1 to indicate the first day of a week on Monday. // Add the long integer time to the time offset of the nth week. time + = 24*3600000; // week 1 Start Time var nextYear = new Date (parseInt (year, 10) + 1, "0", "1"); var nextWeek = nextYear. getDay (); var lastcnt = 0; // obtain the number of days from the last week's start time to the weekend if (nextWeek = 0) {lastcnt = 6 ;} else if (nextWeek = 1) {lastcnt = 0;} else if (nextWeek = 2) {lastcnt = 1;} else if (nextWeek = 3) {lastcnt = 2;} else if (nextWeek = 4) {lastcnt = 3;} else if (nextWeek = 5) {lastcnt = 4 ;} else if (nextWeek = 6) {lastcnt = 5;} if (weeks = 1) {// special processing for week 1st // reset the date object to time var start = date. format ("MM dd, yyyy"); date. setTime (time-24*3600000); return start + '--' + date. format ("yyyy MM dd");} else if (weeks = 54) {// 54th special weekly processing var start = time + (weeks-2) * 7*24*3600000; // the start time of week 54th var end = time + (weeks-2) * 7*24*3600000 + lastcnt * 24*3600000-24*3600000; // end time of week 53rd // reset the date object to time date. setTime (start); var _ start = date. format ("MM dd, yyyy"); date. setTime (end); var _ end = date. format ("MM dd, yyyy"); return _ start + '--' + _ end;} else {var start = time + (weeks-2) * 7*24*3600000; // the nth week start time var end = time + (weeks-1) * 7*24*3600000-24*3600000; // end time of week n // reset the date object to time date. setTime (start); var _ start = date. format ("MM dd, yyyy"); date. setTime (end); var _ end = date. format ("MM dd, yyyy"); return _ start + '--' + _ end ;}}}`
:

Jsp part:

`<div id="watch_date" class="menu-content watch_date" style="width:355px;height:360px;display:none;">  <div style="width:355px;height:30px;line-height:27px;text-align:center;background-color:#E0ECFF;">  <input id="year" class="easyui-numberspinner" required="required" value="\${nf['MAXNF'] }" data-options="max:\${nf['MAXNF'] },min:\${nf['MINNF'] }" style="width:60px;line-height: 0px;">  </div>  <div id="week">  <c:forEach begin="1" end="54" var="v" step="1">  <div class="nodata" data="\${v}">\${v}</div>  </c:forEach>  </div>    </div>`
Block weekly click events without data:

Idea: it is actually very simple, just to control the style. First, set the weekly style as unclickable, and then add clickable style based on weekly recycling of data, click "practice" to determine blocking.

Example of a custom space:

How can I return weekly EXCEL Problems Based on the date?

WEEKNUM converts the serial number to the number WEEKNUM (serial_num, return_type) that represents the week of the year)
Return_type indicates that the week starts from
One week starts on Sunday. The number of days in a week ranges from 1 to 7.
2 weeks start from Monday. The number of days in a week ranges from 1 to 7.

For example, if A1 is a date and you want to display the Week of the date in B1, the B1 formula is:
= Weeknum (A1, 1)

Obtain all the dates of the Week (from Monday to Sunday) of the date by date.

// Obtain the date of the last week of the specified date
Public static string [] GetDate (string date) // specifies the selected date.
{
String [] dayOfWeek = new string [7];
DateTime d = Convert. ToDateTime (date );
// DateTime w1 = d. AddDays (1-(int) d. DayOfWeek); // Monday is the first day of a week.
DateTime w1 = d. AddDays (-(int) d. DayOfWeek); // locates the first day of a week on Sunday.
DayOfWeek [0] = w1.tow.datestring ();
For (int I = 1; I <7; I ++)
{
DayOfWeek [I] = w1.tow.datestring ();
}
// String [] a = {w1.ToString (), w2.ToString ()};
Return dayOfWeek;
}

Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.