Getting a short day name

MaiOM picture MaiOM · Sep 21, 2012 · Viewed 37.5k times · Source

I was wondering on how to write a method that will return me a string which will contain the short day name, example:

    public static string GetShortDayName(DayOfWeek day)

now if i call:

        string monday = GetShortDayName(DayOfWeek.Monday);

I will get back "mo" if culture is en, or "lu" if culture is at example it.

Answer

Jon Skeet picture Jon Skeet · Sep 21, 2012

You can use DateTimeFormatInfo.AbbreviatedDayNames. For example:

string[] names = culture.DateTimeFormat.AbbreviatedDayNames;
string monday = names[(int) DayOfWeek.Monday];