日期时间帮助 [英] Date time help

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

问题描述

我想以字符串形式获取当前日期,例如2011年1月18日
我正在使用

string date = DateTime.Now.Date.ToShortDateString();



但它返回的是2011年1月18日,星期二,我只想要日期,而不是天

解决方案

有关不同格式,请参见此处:
http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8- F859AA20581F.htm [ ^ ]

我想你想要的是:

 字符串 date = DateTime.Now.ToString("  MM/dd/yyyy"); 


在控制面板/区域属性"部分中检查您的短日期设置.

您可以使用string.Format来获取日期时间的任何可想到的自定义形式:

阅读此内容: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx [ ^ ].

如果仍然需要符合某些区域性的格式设置,可以使用DateTime.Now.ToString(Globalization.CultureInfo.CreateSpecificCulture(cultureName);否则,请使用DateTime.Now.ToString(Globalization.CultureInfo.CreateSpecificCulture(cultureName).阅读此内容:

http://msdn.microsoft.com/en-us/library/system. globalization.cultureinfo.createspecificculture.aspx [ ^ ]


I want to take current date in a string eg January,18,2011
I m using

string date = DateTime.Now.Date.ToShortDateString();



but it is returning Tuesday,January,18,2011 i only want Date not Day

how can this accomplish?

解决方案

See here for the different formats:
http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm[^]

I think what you want is:

string date = DateTime.Now.ToString("MM/dd/yyyy");


Check your short date settings in the Control panel / regional properties section.


You can use string.Format to get any thinkable custom form of the date-time:

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

If you still need formatting conforming to some culture, you can use DateTime.Now.ToString(Globalization.CultureInfo.CreateSpecificCulture(cultureName); read this:

http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.createspecificculture.aspx[^]


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

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