DateTime.ParseExact()的问题

时间:2015-08-16 01:27:38

标签: c#

我遇到下一个解析问题:

Time="4/1/2015 7:10:31 a m"
FechaLeida = DateTime.ParseExact(Time, "M/d/yyyy hh:mm:ss tt", new CultureInfo("en-US"));

我得到了一个例外:

  

此字符串无法识别为有效日期时间

关于我做错了什么的想法?

1 个答案:

答案 0 :(得分:2)

您的格式和日期不是macthing,您需要在一小时内使用07,因为您提到hh并且空格为a m

var time="4/1/2015 07:10:31 am"; 
FechaLeida = DateTime.ParseExact(time, "M/d/yyyy hh:mm:ss tt", new CultureInfo("en-US"));

OR

var time="4/1/2015 7:10:31 am"; 
FechaLeida = DateTime.ParseExact(time, "M/d/yyyy h:mm:ss tt", new CultureInfo("en-US"));
相关问题