C#: System.DayOfWeek output localized Weekday name
I have a plain DayOfWeek value and want to output the corresponding localized weekday name. Since it is an enum, there is no localization, says Microsoft. This is by design and will not be implemented in any way. I shall use DateTime’s .ToString(“dddd”). Alright, but I have no DateTime object from which I get the DayOfWeek. No problem. Here’s a workaround:
private string GetLocalizedWeekdayName(DayOfWeek d)
{
DateTime dt = DateTime.Today;
while (dt.DayOfWeek != d)
{
dt = dt.AddDays(1);
}
return dt.ToString("dddd");
}