C # obtain the week in the year/obtain the start date and end date of the week based on the week in the year

Source: Internet
Author: User
/// <Summary> /// obtain the week of the year /// </Summary> /// <Param name = "DT"> date </param> /// <returns> </returns> Public static int getweekofyear (datetime DT) {system. globalization. gregoriancalendar GC = new system. globalization. gregoriancalendar (); int weekofyear = GC. getweekofyear (DT, system. globalization. calendarweekrule. firstday, dayofweek. monday); Return weekofyear;} // <summary> // obtain the start date and end date of the week based on the week of the year. /// </Summary> /// <Param name = "year"> </param> /// <Param name = "weeknumber"> </param> /// <Param name = "culture"> </param> // <returns> </returns> Public static tuple <datetime, datetime> getfirstenddayofweek (INT year, int weeknumber, system. globalization. cultureinfo culture) {system. globalization. calendar calendar = culture. calendar; datetime firstofyear = new datetime (year, 1, 1, calendar); dateti Me targetday = calendar. addweeks (firstofyear, weekNumber-1); dayofweek firstdayofweek = culture. datetimeformat. firstdayofweek; while (targetday. dayofweek! = Firstdayofweek) {targetday = targetday. adddays (-1);} return tuple. Create <datetime, datetime> (targetday, targetday. adddays (6 ));}

  

C # obtain the week in the year/obtain the start date and end date of the week based on the week in the year

Related Article

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.