Chris Fulstow Chris Fulstow - 1 year ago 96
C# Question

Getting current culture day names in .NET

Is it possible to get the

's weekdays from
, but returning Monday as first day of the week instead of Sunday. And, if the current culture isn't English (i.e. the ISO code isn't "en") then leave it as default.

By default

[0]: "Sunday"
[1]: "Monday"
[2]: "Tuesday"
[3]: "Wednesday"
[4]: "Thursday"
[5]: "Friday"
[6]: "Saturday"

But I need:

[0]: "Monday"
[1]: "Tuesday"
[2]: "Wednesday"
[3]: "Thursday"
[4]: "Friday"
[5]: "Saturday"
[6]: "Sunday"

Answer Source

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" };
        return CultureInfo.CurrentCulture.DateTimeFormat.DayNames;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download