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

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

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

任何的建议……


当前回答

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

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

其他回答

你需要GetAbbreviatedMonthName

缩写月份名称:“Aug”

DateTimeFormatInfo。gettabbreviatedmonthname方法(Int32)

返回指定月份的特定于区域性的缩写名称 基于与当前DateTimeFormatInfo相关联的区域性 对象。

string monthName = CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(8)

完整月份名称:“August”

DateTimeFormatInfo。方法(Int32)

返回指定月份的特定于区域性的全名 与当前DateTimeFormatInfo对象关联的区域性。

string monthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(8);

对于短月份名称使用:

string monthName = new DateTime(2010, 8, 1)
    .ToString("MMM", CultureInfo.InvariantCulture);

对于西班牙文化(“es”)的长/完整月份名称:

string fullMonthName = new DateTime(2015, i, 1).ToString("MMMM", CultureInfo.CreateSpecificCulture("es"));

将GetMonthName替换为GetAbbreviatedMonthName,使其为:

string strMonthName = mfi.GetAbbreviatedMonthName(8);

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

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