Week of Year C# Datetime

后端 未结 6 937
情深已故
情深已故 2020-12-20 15:37

I have following code to get the weeknumber of the year given in the DateTime object Time

    public static int WeeksInYear(DateTime date)
    {
        Grego         


        
6条回答
  •  一整个雨季
    2020-12-20 16:08

    You can use the class Week of the Time Period Library for .NET which supports supports the ISO 8601 week numbering:

    TimeCalendar calendar = new TimeCalendar(
        new TimeCalendarConfig { YearWeekType = YearWeekType.Iso8601 } );
    Week week = new Week( new DateTime( 2012, 01, 01 ), calendar );
    Console.WriteLine( "week #: ", week.WeekOfYear );
    

提交回复
热议问题