Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anything in .NET that gets the abbreviation of all weekdays specific to culture?

Tags:

c#

datetime

I need the weekdays abbreviation in different cultures. I have it in spanish already (hardcoded). Are there something already in .NET that has it already?

 //string[] days = { "lunes", "martes", "miércoles", "jeuves", "viernes", "sábado", "domingo" };



    string[] days = { "L", "M", "X", "J", "V", "S", "D" };
like image 734
marko Avatar asked Oct 01 '13 11:10

marko


2 Answers

You're probably looking for DateTimeFormatInfo.AbbreviatedDayNames

Gets or sets a one-dimensional array of type String containing the culture-specific abbreviated names of the days of the week.

or DateTimeFormatInfo.ShortestDayNames

Gets or sets a string array of the shortest unique abbreviated day names associated with the current DateTimeFormatInfo object.

For example:

CultureInfo.CurrentCulture.DateTimeFormat.AbbreviatedDayNames

returns

enter image description here

on a de-DE system.

like image 132
sloth Avatar answered Nov 02 '22 05:11

sloth


Try to observe the CultureInfo

var culture = System.Globalization.CultureInfo.CurrentCulture;
var dayNames = culture.DateTimeFormat.AbbreviatedDayNames;
var shortNames = culture.DateTimeFormat.ShortestDayNames;
...

And it is there for any culture:

System.Globalization.CultureInfo.GetCultureInfo("cs")
like image 4
Radim Köhler Avatar answered Nov 02 '22 05:11

Radim Köhler