Getting current culture day names in .NET

后端 未结 9 932
情书的邮戳
情书的邮戳 2021-01-11 18:32

Is it possible to get the CurrentCulture\'s weekdays from DateTimeFormatInfo, but returning Monday as first day of the week instea

9条回答
  •  时光取名叫无心
    2021-01-11 19:08

    This should also work nice.

        public static List Days
        {
            var abbDayNames = CultureInfo.CurrentCulture.DateTimeFormat.AbbreviatedDayNames;
    
            var days = new string[7];
            var firstDayOfWeek = (int)DayOfWeek.Monday;
            for (int i = 6; i>= 0; i--)
            {
                days[i] = abbDayNames[(firstDayOfWeek + i) % 7];
            }
    
            return new List(days);
        }
    

提交回复
热议问题