为什么这个日期转换失败?
string CompletedDateTime ="2016-01-08 03:47:03.000";
DateTime cDate = DateTime.ParseExact("yyyy-MM-dd HH:mm:ss:fff", CompletedDateTime , null);
异常:字符串不能识别为有效的DateTime。
发布于 2016-01-07 23:44:32
你可以试试这个:
DateTime cDate = DateTime.ParseExact(CompletedDateTime, "yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
问题是你在传递的参数中使用了错误的顺序。该方法的签名如下:
public static DateTime ParseExact(
string s,
string format,
IFormatProvider provider
)
有关此方法的更多信息,请查看这里。
此外,你也有一个小错误的格式,你通过。没有任何:fff
。有.fff
。
发布于 2016-01-07 23:46:35
DateTime.ParseExact(CompletedDateTime, "yyyy-MM-dd HH:mm:ss.fff", null);
https://stackoverflow.com/questions/34667190
复制相似问题