At the moment I\'m creating a DateTime
for each month and formatting it to only include the month.
Is there another or any better way to do this?
You can get a list of localized months from Thread.CurrentThread.CurrentCulture.DateTimeFormat.MonthNames
and invariant months from DateTimeFormatInfo.InvariantInfo.MonthNames
.
string[] localizedMonths = Thread.CurrentThread.CurrentCulture.DateTimeFormat.MonthNames;
string[] invariantMonths = DateTimeFormatInfo.InvariantInfo.MonthNames;
for( int month = 0; month < 12; month++ )
{
ListItem monthListItem = new ListItem( localizedMonths[month], invariantMonths[month] );
monthsDropDown.Items.Add( monthListItem );
}
There might be some issue with the number of months in a year depending on the calendar type, but I've just assumed 12 months in this example.