Best way to turn an integer into a month name in c#?

Viewed 68331

Is there a best way to turn an integer into its month name in .net?

Obviously I can spin up a datetime to string it and parse the month name out of there. That just seems like a gigantic waste of time.

6 Answers

Why not just use somedatetime.ToString("MMMM")?

Updated with the correct namespace and object:

//This was wrong
//CultureInfo.DateTimeFormat.MonthNames[index];

//Correct but keep in mind CurrentInfo could be null
DateTimeFormatInfo.CurrentInfo.MonthNames[index];

You can use a static method from the Microsoft.VisualBasic namespace:

string monthName = Microsoft.VisualBasic.DateAndTime.MonthName(monthInt, false);
Related