一个月INT转换为一个月的名称 [英] Convert month int to month name

查看:198
本文介绍了一个月INT转换为一个月的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是试图使用的DateTime 结构改造1和12之间的整数到abbrieviated月份名称。

下面是我的尝试:

 日期时间得到月= DateTime.ParseExact(Month.ToString()
                       的M,CultureInfo.CurrentCulture);
返回getMonth.ToString(MMM);
 

不过,我得到一个出现FormatException 在第一行,因为该字符串不是有效的的DateTime 。谁能告诉我如何做到这一点?

解决方案

  CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(1);
 

请参阅<一href="http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.getmonthname.aspx">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" ) );

这篇关于一个月INT转换为一个月的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆