将日期转换为MM,yyyy [英] convert date to MM,yyyy

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

问题描述

海,
我需要将特殊日期转换为字符串.

例如:txtbox.text();(2012年5月15日)至2012年5月

请帮助我

Hai,
I need to convert paricular date to string.

Ex:txtbox.text();(15/05/2012) to May,2012

Please help me

推荐答案

DateTime对象可以设置为类似于
的字符串
A DateTime object can be set to string like
txtbox.text = myDateTime.ToString("MMM,yyyy");


使用具有自定义格式的DateTime.ToString方法(请参阅 ^ ]),例如
Use the DateTime.ToString method with a custom format (see MSDN[^]), for instance
DateTime dt = new DateTime(2012, 5, 15);
txtbox.Text = dt.ToString("MMM,yyyy");


如果您想采取其他方法,即不将DateTime对象格式化为String,而是将String转换为DateTime对象,则可以使用DateTime.解析(...)函数.这些参考在MSDN中都有,您应该会很好地使用它们.
If you want to do the other way around, i.e. not to format a DateTime object into String, but to convert a String into a DateTime object, you can use DateTime.Parse(...) functions. The references are all there in MSDN you should be fine with them.


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

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