如何将一种类型的dateTime值转换为另一种类型的dateTime [英] How to convert One type of dateTime value to another type of dateTime Fromat
本文介绍了如何将一种类型的dateTime值转换为另一种类型的dateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有这样的日期:"2010年4月5日星期一CDT"
我想将此日期定为04/05/2010 22:56:26
如何通过C#进行转换..
Hi ALL,
I have a date like this "Mon Apr 05 22:56:26 CDT 2010"
I would like to get this date as 04/05/2010 22:56:26
How to convert this through C#..
推荐答案
使用
string converted = DateTime.Parse(inputdatestring).ToString("format string");
并在此处查看格式字符串: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx [ ^ ]
and look at the format strings here : http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^]
看看:
自定义日期和时间格式字符串 [标准日期和时间格式字符串 [ DateTime.TryParseExact [ DateTime.ToString [ ^ ]将其转换为使用所需格式的字符串.
请记住,"CDT 2010年4月5日星期一"和"04/05/2010 22:56:26"是字符串,而DateTime是DateTime信息的CLR表示形式.
最好的问候
Espen Harlinn
Have a look at:
Custom Date and Time Format Strings[^]
Standard Date and Time Format Strings[^]
Use DateTime.TryParseExact[^] to convert your input string to a DateTime, and then use DateTime.ToString[^] to convert it to a string using the desired format.
Remember that "Mon Apr 05 22:56:26 CDT 2010" and "04/05/2010 22:56:26" are strings, while DateTime is the CLR representation for DateTime information.
Best regards
Espen Harlinn
检查此
http://www.csharp-examples.net/string-format-datetime/ [ ^ ]
http://www.dotnetperls.com/datetime-format [
Check this
http://www.csharp-examples.net/string-format-datetime/[^]
http://www.dotnetperls.com/datetime-format[^]
这篇关于如何将一种类型的dateTime值转换为另一种类型的dateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文