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

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

问题描述

我试图列出每月的名称,而不是每个月的整数值。 (例如,如果日期是2/2/2002,我想月读出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获取当前月份当我尝试打印当前月份在窗体上,它只是放置相关的整数值的月份,而我想有月份名称。

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- 4.0。

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

推荐答案

尝试 DateTime.Now.ToString(MMMM)

请参阅 MSDN:自定义日期和时间格式其他格式字符串的字符串

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

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