Possible Duplicate:
How to get the MonthName in c#?可能重复:如何获得c#中的月名?
I used the following c# syntax to get month name from month no but i get August
i want only Aug
..
我使用了下面的c#语法来获取月号,但是我得到了我想要的八月。
System.Globalization.DateTimeFormatInfo mfi = new
System.Globalization.DateTimeFormatInfo();
string strMonthName = mfi.GetMonthName(8).ToString();
Any suggestion...
任何的建议……
6 个解决方案
#1
276
For short month names use:
对于较短的月份名称使用:
string monthName = new DateTime(2010, 8, 1)
.ToString("MMM", CultureInfo.InvariantCulture);
For long/full month names for Spanish ("es") culture
用于西班牙语(“es”)文化的长/完整月份名称
string fullMonthName = new DateTime(2015, i, 1).ToString("MMMM", CultureInfo.CreateSpecificCulture("es"));
#2
226
For Abbreviated Month Names : "Aug"
缩写月份名称:“Aug”
DateTimeFormatInfo.GetAbbreviatedMonthName Method (Int32)
DateTimeFormatInfo。GetAbbreviatedMonthName方法(Int32)
Returns the culture-specific abbreviated name of the specified month based on the culture associated with the current DateTimeFormatInfo object.
根据与当前DateTimeFormatInfo对象关联的区域性返回指定月份的特定区域性缩写名。
string monthName = CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(8)
For Full Month Names : "August"
月份名称:“August”
DateTimeFormatInfo.GetMonthName Method (Int32)
DateTimeFormatInfo。GetMonthName方法(Int32)
Returns the culture-specific full name of the specified month based on the culture associated with the current DateTimeFormatInfo object.
根据与当前DateTimeFormatInfo对象关联的区域性返回指定月份的特定区域性全名。
string monthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(8);
#3
81
Replace GetMonthName
with GetAbbreviatedMonthName
so that it reads:
将getmonth替换为ge表化的月度名称,使其为:
string strMonthName = mfi.GetAbbreviatedMonthName(8);
#4
11
You want GetAbbreviatedMonthName
你想要GetAbbreviatedMonthName
#5
6
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(4)
This method return April
这个方法返回4月
If you need some special language, you can add:
如果你需要一些特别的语言,你可以加上:
<system.web>
<globalization culture="es-ES" uiCulture="es-ES"></globalization>
<compilation debug="true"
</system.web>
Or your preferred language.
或你的首选语言。
For example, with es-ES
culture:
例如,与es文化:
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(4)
Returns: Abril
返回:阿布里尔
Returns: Abril
(in spanish, because, we configured the culture as es-ES
in our webconfig
file, else, you will get April
)
返回:Abril(在西班牙语中,因为我们在webconfig文件中配置了es-ES,否则,您将得到4月份)
That should work.
这应该工作。
#6
3
You can get this in following way,
你可以这样得到,
DateTimeFormatInfo mfi = new DateTimeFormatInfo();
string strMonthName = mfi.GetMonthName(8).ToString(); //August
Now, get first three characters
现在,获取前三个字符
string shortMonthName = strMonthName.Substring(0, 3); //Aug
Thanks.
谢谢。
#1
276
For short month names use:
对于较短的月份名称使用:
string monthName = new DateTime(2010, 8, 1)
.ToString("MMM", CultureInfo.InvariantCulture);
For long/full month names for Spanish ("es") culture
用于西班牙语(“es”)文化的长/完整月份名称
string fullMonthName = new DateTime(2015, i, 1).ToString("MMMM", CultureInfo.CreateSpecificCulture("es"));
#2
226
For Abbreviated Month Names : "Aug"
缩写月份名称:“Aug”
DateTimeFormatInfo.GetAbbreviatedMonthName Method (Int32)
DateTimeFormatInfo。GetAbbreviatedMonthName方法(Int32)
Returns the culture-specific abbreviated name of the specified month based on the culture associated with the current DateTimeFormatInfo object.
根据与当前DateTimeFormatInfo对象关联的区域性返回指定月份的特定区域性缩写名。
string monthName = CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(8)
For Full Month Names : "August"
月份名称:“August”
DateTimeFormatInfo.GetMonthName Method (Int32)
DateTimeFormatInfo。GetMonthName方法(Int32)
Returns the culture-specific full name of the specified month based on the culture associated with the current DateTimeFormatInfo object.
根据与当前DateTimeFormatInfo对象关联的区域性返回指定月份的特定区域性全名。
string monthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(8);
#3
81
Replace GetMonthName
with GetAbbreviatedMonthName
so that it reads:
将getmonth替换为ge表化的月度名称,使其为:
string strMonthName = mfi.GetAbbreviatedMonthName(8);
#4
11
You want GetAbbreviatedMonthName
你想要GetAbbreviatedMonthName
#5
6
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(4)
This method return April
这个方法返回4月
If you need some special language, you can add:
如果你需要一些特别的语言,你可以加上:
<system.web>
<globalization culture="es-ES" uiCulture="es-ES"></globalization>
<compilation debug="true"
</system.web>
Or your preferred language.
或你的首选语言。
For example, with es-ES
culture:
例如,与es文化:
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(4)
Returns: Abril
返回:阿布里尔
Returns: Abril
(in spanish, because, we configured the culture as es-ES
in our webconfig
file, else, you will get April
)
返回:Abril(在西班牙语中,因为我们在webconfig文件中配置了es-ES,否则,您将得到4月份)
That should work.
这应该工作。
#6
3
You can get this in following way,
你可以这样得到,
DateTimeFormatInfo mfi = new DateTimeFormatInfo();
string strMonthName = mfi.GetMonthName(8).ToString(); //August
Now, get first three characters
现在,获取前三个字符
string shortMonthName = strMonthName.Substring(0, 3); //Aug
Thanks.
谢谢。