将月份转换为月份名称 [英] Convert month int to month name
本文介绍了将月份转换为月份名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是试图使用 DateTime
结构将一个整数介于1到12之间变成一个abbrieviated月份名称。
I was simply trying to use the DateTime
structure to transform an integer between 1 and 12 into an abbrieviated month name.
这是我试过的:
DateTime getMonth = DateTime.ParseExact(Month.ToString(),
"M", CultureInfo.CurrentCulture);
return getMonth.ToString("MMM");
但是,我第一次收到一个 FormatException
因为字符串不是有效的 DateTime
。任何人都可以告诉我怎么做?
However I get a FormatException
on the first line because the string is not a valid DateTime
. Can anyone tell me how to do this?
推荐答案
CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(1);
请参阅以上了解更多详情。
或
DateTime dt = DateTime.Now;
Console.WriteLine( dt.ToString( "MMMM" ) );
或者如果您想获得特定于文化的缩写名称。 / p>
Or if you want to get the culture-specific abbreviated name.
GetAbbreviatedMonthName(1);
这篇关于将月份转换为月份名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文