none
How to get abbreviate Names of week into List with culture info RRS feed

  • Question

  • I need get the abbreviate Names of week into sorted list passing start day to order.

    I try:

    var daysNames = new CultureInfo(culture).DateTimeFormat
                .AbbreviatedDayNames
                .Select((item) => new CalendarDaysItem(item.ToUppercaseFirst()))
                .ToList();

    But i cant ordered

    And i have:

                var daysOfWeek = Enum.GetValues(typeof(DayOfWeek))
                    .Cast<DayOfWeek>()
                    .OrderBy(x => (x - firstDayOfWeek + 7) % 7);
    But i can't define the culture info to set "pt-PT"


    Wednesday, August 8, 2018 8:57 AM

Answers

  • Hi Fabio A M Santos,

    Please check the following code, we could convert to special culture via the method named DateTimeFormatInfo.CurrentInfo.GetAbbreviatedDayName

    Thread.CurrentThread.CurrentCulture = new CultureInfo("pt-PT");
    
    
                DayOfWeek firstDayOfWeek = DayOfWeek.Monday;
                var daysOfWeek = Enum.GetValues(typeof(DayOfWeek))
                   .Cast<DayOfWeek>()
                   .OrderBy(x => (x - firstDayOfWeek + 7) % 7)
                   .Select(x => DateTimeFormatInfo.CurrentInfo.GetAbbreviatedDayName(x))
                   .ToList();

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, August 9, 2018 3:20 AM
    Moderator

All replies

  • I need start by monday, or sunday depend on parameter pass to function
    Wednesday, August 8, 2018 9:52 AM
  • Hi Fabio A M Santos,

    Please check the following code, we could convert to special culture via the method named DateTimeFormatInfo.CurrentInfo.GetAbbreviatedDayName

    Thread.CurrentThread.CurrentCulture = new CultureInfo("pt-PT");
    
    
                DayOfWeek firstDayOfWeek = DayOfWeek.Monday;
                var daysOfWeek = Enum.GetValues(typeof(DayOfWeek))
                   .Cast<DayOfWeek>()
                   .OrderBy(x => (x - firstDayOfWeek + 7) % 7)
                   .Select(x => DateTimeFormatInfo.CurrentInfo.GetAbbreviatedDayName(x))
                   .ToList();

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, August 9, 2018 3:20 AM
    Moderator