Getting current culture day names in .NET

后端 未结 9 888
情书的邮戳
情书的邮戳 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 18:47

    You can use custom cultures to create a new culture based off an existing one. To be honest, though, I'd say that's probably a bit heavy-handed. The "simplest" solution may just be something like:

    public string[] GetDayNames()
    {
        if (CultureInfo.CurrentCulture.Name.StartsWith("en-"))
        {
            return new [] { "Monday", "Tuesday", "Wednesday", "Thursday",
                            "Friday", "Saturday", "Sunday" };
        }
        else
        {
            return CultureInfo.CurrentCulture.DateTimeFormat.DayNames;
        }
    }
    

提交回复
热议问题