beta.blog

Programming

C# – Convert Month Number to Month Name

by on Jul.30, 2012, under Programming

This is how I get the name of a month as a string when I know the int index of the month only:

string month = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(1);

Another way is to use the ToString() method of the DateTime class. I’m not sure wheter or not this one is culture-specific as well.

string month = DateTime.Parse("January 01, 1900").ToString("MMMM");

or

string month = new DateTime(1900, month, 1).ToString("MMMM");
Leave a Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!