Home > Blockchain >  how can I match an day integer to AbbreviatedDayNames
how can I match an day integer to AbbreviatedDayNames

Time:11-04

I have the following function that return a list of the short day names in a week.

        public static string[] GetDayNames(string cultureCode)
    {
        var culture = CultureInfo.CreateSpecificCulture(cultureCode);
        string[] names = culture.DateTimeFormat.AbbreviatedDayNames;
        return names;
    }

I now need to match a specific dates day (integer value) to the correct AbbreviatedDayName, how can I do that?

CodePudding user response:

The only way to do this is to convert the day into a date time and then to get the AbbreviatedDayName:

var ab = culture.DateTimeFormat.AbbreviatedDayNames[((int)dt.DayOfWeek)];

CodePudding user response:

I now need to match a specific dates day (integer value) to the correct AbbreviatedDayName, how can I do that?

This is not possible. Not every 1st of every month is the same day of the week. You need to observe the entire date (year, month and day) before you can take a stab at what day of the week it is.

  • Related