c#中如何把string类型转化为datatime

2024-12-27 15:00:33
推荐回答(5个)
回答1:

我这里有种思路,刚学到得,希望对你有用,抛砖引玉
string convertTime = "2012-12-12 13:00:21 872";
DateTime mdate1 = DateTime.ParseExact(convertTime, "yyyy-MM-dd HH:mm:ss fff", null);
convertTime = "2012:12:12 13-00-21 872";
mdate1 = DateTime.ParseExact(convertTime, "yyyy:MM:dd HH-mm-ss fff", null);

回答2:

Convert.ToDateTime("2010-01-01");

回答3:

Convert.ToDateTime(string)

回答4:

//{2012-12-12 00:00:00}
string time = "";
DateTime datetime;
time = "2012-12-12";
datetime = Convert.ToDateTime(time);
time = "2012.12.12";
datetime = Convert.ToDateTime(time);
time = "12.12";
datetime = Convert.ToDateTime(time);

回答5:

应该是formate吧