Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get an array of months in c#

Tags:

c#

I want to get the month array in c#.
somthing like this : { January , February , ... , December }
How can I do this? please send me codes in C#. thanks

like image 358
LIX Avatar asked Nov 05 '09 06:11

LIX


1 Answers

string[] monthNames = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.MonthNames;

foreach (string m in monthNames) // writing out
{
    Console.WriteLine(m);
}

Output:

January
February
March
April
May
June
July
August
September
October
November
December

Update:
Do note that for different locales/cultures, the output might not be in English. Haven't tested that before though.

For US English only:

string[] monthNames = (new System.Globalization.CultureInfo("en-US")).DateTimeFormat.MonthNames;
like image 111
o.k.w Avatar answered Nov 13 '22 13:11

o.k.w