How can I determine the week number of a certain date?

后端 未结 3 2109
小鲜肉
小鲜肉 2020-11-30 11:38

I\'m trying to make a calendar using wpf. By using itemsPanel and more, I have a grid with 7 columns(sunday-saturday) and 6 rows(week# of month). If i can find the starting

3条回答
  •  旧巷少年郎
    2020-11-30 12:13

    With @Polynomial answer, I have this error:

    An object reference is required for the non-static field, method, or property...

    If you instanciate GregorianCalendar before then you can call the method GetWeekOfYear !

    private static int GetWeekNumber(DateTime time)
    {
        GregorianCalendar cal = new GregorianCalendar();
        int week = cal.GetWeekOfYear(time, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday);
        return week;
    }
    

提交回复
热议问题