Based on year, month, week, calculation specific one day (Monday)

Source: Internet
Author: User

#region old based on year, month, week, calculate specific day

<summary>
Old based on year, month, week, calculate specific day
</summary>
public Object Showweekdate (int year, int month)
{
list<object> lists = new list<object> ();
String str = "";
The first day of the current month
DateTime weekstart = new DateTime (year, month, 1);
The last day of the month
DateTime monend = weekstart.addmonths (1). AddDays (-1);
int i = 1;
The first day of the current month is the days of the week
int dayOfWeek = Convert.ToInt32 (weekStart.DayOfWeek.ToString ("D"));
End date of the first week of the month
DateTime WeekEnd = DayOfWeek = = 0? WeekStart:weekStart.AddDays (7-dayofweek);
str + = "First" + i + "Week start Date:" + weekstart.toshortdatestring () + "End Date:" + weekend.toshortdatestring () + "\ n";
var dateSpanWeek1 = new {StartDate = Weekstart.toshortdatestring (), EndDate = Weekend.toshortdatestring ()};
Lists. ADD (DATESPANWEEK1);
When the date is less than or equal to the last day of the month
while (Weekend.adddays (1) <= monend)
{
i++;
Start time of the week
Weekstart = weekend.adddays (1);
End time of the week
WeekEnd = weekend.adddays (7) > Monend? MonEnd:weekEnd.AddDays (7);
str + = "First" + i + "Week start Date:" + weekstart.toshortdatestring () + "End Date:" + weekend.toshortdatestring () + "\ n";
var dateSpanWeek2 = new {StartDate = Weekstart.toshortdatestring (), EndDate = Weekend.toshortdatestring ()};
Lists. ADD (DATESPANWEEK2);
}
STR + + year + "years" + month + "Monthly Total" + i + "week \ n";
return lists;
}

#endregion old based on year, month, week, calculate specific day

Based on year, month, week, calculation specific one day (Monday)

Contact Us

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.