Time Processing, java Time Processing
The time is processed by the time or the date of the corresponding day of the week.
1. International WeekDay is the sequence from Sunday to Saturday
2. In addition, the DayOfWeek enumerated values of C # are from 0 to 6 in sequence, that is, the enumerated values on Monday are 1.
3. algorithm pattern: if it is not Monday, you need to obtain the last Monday, but seven days a week. Monday is the demarcation point, and the day is Tuesday and later. The algorithm is to subtract the N number of the day and Add 1 after 7 days, and then add 1 after 7 days.
Using this algorithm, you can create a general method to obtain the date of the last week of any specified date. The Code is as follows:
pubilc DateTime getWeekUpOfDate(DateTime dt,DayOfWeek weekday,int Number){ int wd1=(int)weekday; int wd2=(int)dt.DayOfWeek; return wd2==wd1?dt.AddDay(7*Number):dt.AddDay(7*Number-wd2+wd1);}
Parameter description: The date on which dt is specified, and weekday is the number of weeks of calculation (upper, current, and lower ).
The method is called as follows:
DateTime dt = getWeekUpOfDate (DateTime. Now, DayOfWeek. Monday,-1 );
This is the last Monday of the current date.
DateTime dt = getWeekUpOfDate (DateTime. Now, DayOfWeek. Monday,-2 );
This is the last Monday of the current date.
DateTime dt = getWeekUpOfDate (DateTime. Now, DayOfWeek. Monday, 1 );
This is the next Monday of the current date.
DateTime dt = getWeekUpOfDate (DateTime. Now, DayOfWeek. Monday, 0 );
This is the date of Monday of the week.
As you cannot share your blog, record it as you go
Source: http://zhidao.baidu.com/link? Url = Response