Friday, December 16, 2011

Get Month Names using C#.NET

This article explains how to get all month names of the year using C#.NET. First create an instance of the class DateTimeFormatInfo and get its CurrentInfo. There is property called MonthNames in the DateTimeFormatInfo which returs an array of month names.

using System.Globalization;
using System.Collections.Generic;

public
ListItem[] GetMonthNamesList()
{
DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo;
string[] _months = dfi.MonthNames;
List<ListItem> _monthNamesList = new List<ListItem>();
for (int i = 0; i <= 11; i++)
{
_monthNamesList.Add(
new ListItem(_months[i], (i + 1).ToString()));
}
return _monthNamesList.ToArray();
}

Output sample:

January
February
March
April
May
June
July
August
September
October
November
December

No comments:

Codeigniter Shield Authorization

Codeigniter Shield Authorization CodeIgniter Shield is the official authentication and authorization framework for CodeIgniter 4. It provide...