Friday, December 10, 2010

Get list of Months Names in the current Thread language

One of the functions which are required in the localized applications is to get the list of months names in the current culture language.
To do this, some people do this using resources and add it manually to the control (DropDownList, ListBox, etc...), but you can accomplish this by the following single line of code which returns the months names translated to the current Thread culture.
Thread.CurrentThread.CurrentCulture.DateTimeFormat.MonthNames.Take(12);

Demo:
If the current thread culture is “fr-FR” it returns:

If the current thread culture is “de-DE” it returns:


If the current thread culture is “ar-EG” it returns:

I hope that this saves some of your valuable time.

No comments:

Post a Comment