Time Processing, java Time Processing

Source: Internet
Author: User

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

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.