由网友(好久不贱)分享简介:我只是试图使用的DateTime 结构改造1和12之间的整数到abbrieviated月份名称。下面是我的尝试:日期时间得到月= DateTime.ParseExact(Month.ToString()的M,CultureInfo.CurrentCulture);返回getMonth.ToString(MMM);不过...
我只是试图使用的DateTime
结构改造1和12之间的整数到abbrieviated月份名称。
下面是我的尝试:
日期时间得到月= DateTime.ParseExact(Month.ToString()
的M,CultureInfo.CurrentCulture);
返回getMonth.ToString(MMM);
不过,我得到一个出现FormatException
在第一行,因为该字符串不是有效的的DateTime
。谁能告诉我如何做到这一点?
CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(1);
请参阅Here了解更多详情。
或
DateTime的DT = DateTime.Now;
Console.WriteLine(dt.ToString(MMMM));
I was simply trying to use the DateTime
structure to transform an integer between 1 and 12 into an abbrieviated month name.
Here is what I tried:
DateTime getMonth = DateTime.ParseExact(Month.ToString(),
"M", CultureInfo.CurrentCulture);
return getMonth.ToString("MMM");
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);
See Here for more details.
Or
DateTime dt = DateTime.Now;
Console.WriteLine( dt.ToString( "MMMM" ) );
相关推荐
最新文章