C# Cultures: Localize DayOfWeek?

前端 未结 1 445
心在旅途
心在旅途 2020-12-30 20:22

How do I localize a DayOfWeek other than today?
The following works just fine for the current day:

DateTime.Now.ToString(\"ffffdd\", new CultureInfo(\"it-I         


        
相关标签:
1条回答
  • 2020-12-30 20:32

    How about

    DateTimeFormatInfo.CurrentInfo.GetDayName( dayOfWeek )
    

    or

    DateTimeFormatInfo.CurrentInfo.GetAbbreviatedDayName( dayOfWeek )
    

    Simply takes a DayOfWeek enumeration and returns string that is the name in the current culture.

    Edit:

    If you're looking for a specific culture it would be

    var cultureInfo = new CultureInfo( "it-IT" );
    var dateTimeInfo = cultureInfo.DateTimeFormat;
    

    then you can call GetDayName or GetAbbreviatedDayName as you choose.

    There's even a AbbreviatedDayNames/DayNames arrays if you want them all

    0 讨论(0)
提交回复
热议问题