Convert.ToDateTime,以任何方式描绘月和年字段C#? [英] Convert.ToDateTime , any way to depict month and year fields C#?
本文介绍了Convert.ToDateTime,以任何方式描绘月和年字段C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下令人难以置信的陈述:
I have the following wonderfully unreliable statement:
string LastsuccessfuldownloadDateTime = "04.07.2009 19:21:36"
DateTime myDate = Convert.ToDateTime(LastsuccessfuldownloadDateTime);
是否可以在转换中显式描述日期和月份字段?
因为我的月和日字段正在交换....
Is it possible to depict the day and month fields explicitly in the conversion? Because my month and day fields are getting swapped....
谢谢
推荐答案
您可以使用DateTime.ParseExact():
You can use DateTime.ParseExact():
// for European format (day followed by month)
DateTime myDate = DateTime.ParseExact(LastsuccessfuldownloadDateTime ,
"dd.MM.yyyy HH:mm:ss", null);
这篇关于Convert.ToDateTime,以任何方式描绘月和年字段C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文