/// <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