可能的重复: 如何在c#中获得MonthName ?

我使用下面的c#语法从月份中获取月份名称,没有,但是我得到了八月,我只想要八月。

System.Globalization.DateTimeFormatInfo mfi = new 
System.Globalization.DateTimeFormatInfo();
string strMonthName = mfi.GetMonthName(8).ToString();

任何的建议……


当前回答

你可以用下面的方法得到它,

DateTimeFormatInfo mfi = new DateTimeFormatInfo();
string strMonthName = mfi.GetMonthName(8).ToString(); //August

现在,获取前三个字符

string shortMonthName = strMonthName.Substring(0, 3); //Aug

其他回答

这应该返回月份索引(1-12)中的月份文本(January - December)

int monthNumber = 1; //1-12  
string monthName = new DateTimeFormatInfo().GetMonthName(monthNumber);

你需要GetAbbreviatedMonthName

你也可以这样做来获取当前月份:

string monthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.Now.Month);

将GetMonthName替换为GetAbbreviatedMonthName,使其为:

string strMonthName = mfi.GetAbbreviatedMonthName(8);

你可以用下面的方法得到它,

DateTimeFormatInfo mfi = new DateTimeFormatInfo();
string strMonthName = mfi.GetMonthName(8).ToString(); //August

现在,获取前三个字符

string shortMonthName = strMonthName.Substring(0, 3); //Aug