且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将日期时间转换为正确的格式

更新时间:2023-02-03 16:24:09

如果你不能得到它,你必须先google然后在这里问...



You have to google first if you cant get it then ask here...

select [Date] = convert(char(10), getdate(), 111)

o/p: 2008/09/05


DateTime类有一个ToString方法,它接受一个格式字符串作为参数。

使用此功能,您可以将日期格式化为您想要的任何文本表示。



有关详细信息,请参阅此处: http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx [ ^ ]
The DateTime class has a ToString method which accepts a format string as argument.
Using this you can format the date to any text representation you want.

See here for more details: http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx[^]


DateTime.Now.ToString(MM / dd / yy)

http://www.4guysfromrolla.com/articles/111010-1.aspx [ ^ ]
DateTime.Now.ToString("MM/dd/yy")
http://www.4guysfromrolla.com/articles/111010-1.aspx[^]