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.
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.
you can use a static method from the Microsoft.VisualBasic namespace:
string monthName = Microsoft.VisualBasic.DateAndTime.MonthName(monthInt, false);
Try GetMonthName from DateTimeFormatInfo
http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.getmonthname.aspx
You can do it by:
CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(1);
To get abbreviated month value, you can use Enum.Parse();
Enum.Parse(typeof(Month), "0");
This will produce "Jan" as result.
Remember this is zero-based index.