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?
How to create a custom list of month names in any order
Yes, I'm answering a question from over 10 years ago! :D
Yet, I wanted to add this code snippet on the chance it might help others. It shows how to output a list of month names in any custom order. In my case I needed it to start in October, but you could put the months in any sequence (even have repeating months) by setting the list of integers.
model.Controls = new
{
FiscalMonths = new
{
Value = DateTime.Now.Month,
Options = (new List { 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9 }).Select(p => new
{
Value = p,
Text = DateTimeFormatInfo.CurrentInfo.GetMonthName(p)
})
}
};
And the json output for use in a dropdown:
"FiscalMonths": {
"Value": 10,
"Options": [
{
"Value": 10,
"Text": "October"
},
{
"Value": 11,
"Text": "November"
},
{
"Value": 12,
"Text": "December"
},
{
"Value": 1,
"Text": "January"
},
{
"Value": 2,
"Text": "February"
},
etc ....