将日期月份转换为字符串 [英] Converting date month into string

查看:81
本文介绍了将日期月份转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的编码员,

今天,我试图将今天的日期月份转换为字符串,但没有得到相同的结果,所以我将其用于您的专家那里.

任务:

如果日期类似于2012年8月30日,则08应显示为AUG.
如果日期如2012年10月20日,则10应显示为OCT.

vb.net 2010的内置功能是否可能做到这一点,或者必须以选定的情况或其他方式指定相同的内容.

谢谢&Regards.

Dear Coders,

Today i was trying to convert the today''s date month into string but not getting the same so i am putting this for you expert out there.

The Task:

If date is like 30/08/2012 then the 08 should be shown as AUG.
If date is like 20/10/2012 then the 10 should be shown as OCT.

Is this possible with the inbuilt function of vb.net 2010 or have to specify the same in a select case or some other fashion.

Thanks & Regards.

推荐答案

是的,您可以这样做,这是
Yes you can do that, this is an example how, http://www.dotnetperls.com/datetime-format-vbnet[^]


尝试以下操作:
Try this one:
Dim monthName As String= New DateTime(2012, 08, 30)
    .ToString("MMM", CultureInfo.InvariantCulture)



希望对您有帮助



Hope it helps


Wes和Christian的回答很好.您还应该在MSDN上阅读有关自定义日期格式的更多信息:

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx [ ^ ]
Answers from Wes and Christian are good. You should also read more about Custom Date Formats at MSDN:

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^]


这篇关于将日期月份转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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