DateTime在C#,Silverlight中从int转换为Month名称 [英] DateTime Convert from int to Month Name in C#, Silverlight

查看:136
本文介绍了DateTime在C#,Silverlight中从int转换为Month名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打印出每个月不是整数值的月份的名称。 (例如,如果日期是2002年2月2日,我希望月读出2月而不是2。

I am trying to print out the name of the month not the integer value of each month. (for example if the date is 2/2/2002, I would like the "month" to read out "February" instead of "2."

我正在拉在system.DateTime.now中获取当前月份,当我尝试在表单上打印当前月份时,它只会显示月份的相关整数值,而我想要有Month Name。

I am pulling in the system.DateTime.now to get the current month. When I try to print out the current month on the form, it just puts the correlating integer value for the month, whereas I would like to have the Month Name.

我知道这可以使用switch-case或if语句将数字单独转换为单词值,但我只是想知道是否有一个简单的内置转换命令这将自动告诉应用程序打印出月份的名称,而不是相关的整数值。

I know this can be done using switch-case or if statements to individually convert the numbers into word values, but I was just wondering if there was a simple, built-in conversion command that will automatically tell the application to print out the month's name instead of it's correlating integer value.

我在Visual Studio 2010环境中使用C#-4.0,Silverlight-

I am programming in the Visual Studio 2010 environment using C#-4.0, Silverlight-4.0.

推荐答案

尝试 DateTime.Now.ToString(MMMM)

请参阅 MSDN:自定义日期a d时间格式字符串用于其他格式字符串。

See MSDN: Custom Date and Time Format Strings for other format strings.

这篇关于DateTime在C#,Silverlight中从int转换为Month名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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