如何将日期值格式化为yyyy/MM/dd? [英] How to format date value to yyyy/MM/dd ?

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

问题描述

你好!!


我只想将数据读取器返回的日期格式化为"yyyy/MM/dd"

我有一个DataReader和TextBox,我想在TextBox中设置DataReader值之一.此值表示SQL Server DB中的日期值.我做了以下事情:

Hello !!


I just want to format the returned date from the data reader into "yyyy/MM/dd"

I have a DataReader and TextBox, i want to set one of DataReader values in the TextBox ... This value represents a date value from SQL Server DB. I did the following:

txtDate.Text = Format(DR("ActionDate"),"yyyy/MM/dd")



还有一次我这样做:




and another time I did this:


Dim x As Date
x = DR("ActionDate")
txtDate.Text = x.ToString("yyyy/MM/dd")



以上方法中没有一种能很好地工作..尽管我在MSDN中进行了大量搜索,尝试了10种以上的解决方案,但没有白费了!!



no one of above methods working well .. although I searched a lot in MSDN and I tried more then 10 solutions but no in vain !!

推荐答案

这就是答案与代码示例: http://msdn.microsoft.com/en-us/library/5hh873ya.aspx [ ^ ].

有关更灵活的选项,请参见:类System.Globalization.DateTimeFormatInfo和提供的示例代码: http ://msdn.microsoft.com/zh-CN/library/system.globalization.datetimeformatinfo.aspx [
-SA
Here is the answer with the code sample: http://msdn.microsoft.com/en-us/library/5hh873ya.aspx[^].

For more flexible option, see this: the class System.Globalization.DateTimeFormatInfo and the sample code provided: http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx[^], in particular, pay attention for "SortableDateTimePattern" in the sample code and the class.

—SA


(如果此处使用以下格式:标准日期和时间格式字符串 [ ^ ]不能给您期望的结果,那么您可能需要检查您的区域性设置.
if the formats here: Standard Date and Time Format Strings[^] aren''t giving you the results you expect, then you may need to check your culture settings.


1 .String.Format("{0:dd/MM/yyyy}", DateTime.Now)

26/09/2009

2. String.Format("{0:MM/dd/yyyy}", DateTime.Now)

 09/26/2009


3 . String.Format("{0:dd/MM/yy}", DateTime.Now)

 26/09/09


4. String.Format("{0:t}", DateTime.Now)

 12:22 PM


5.String.Format("{0:F}", DateTime.Now)


Saturday, September 26, 2009 12:22:25 PM


这篇关于如何将日期值格式化为yyyy/MM/dd?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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