[英]String was not recognized as a valid DateTime
DateTime dtEndTime = DateTime.ParseExact(
appToDate,
timeFormats,
null,
System.Globalization.DateTimeStyles.None);
appToDate = 21-02-2013 12:30 AM
string[] timeFormats = {
"dd-MM-yyyy H:m tt",
"dd-MM-yyyy H:mm tt",
"dd-MM-yyyy HH:m tt",
"dd-MM-yyyy HH:mm tt"
};
String was not recognized as a valid DateTime. 字符串未被识别为有效的DateTime。
I suspect the problem is your use of H
combined with tt
. 我怀疑问题是你使用H
结合tt
。 H
and HH
indicate an hour in the range 0-23, where 12 is noon, and therefore PM. H
和HH
表示0-23范围内的一小时,其中12是中午,因此是PM。
I suspect you want h
and hh
instead of H
... although you shouldn't need every combination of h
/ H
/ m
/ mm
. 我怀疑你想h
和hh
代替H
......虽然你不应该需要的每一种组合h
/ H
/ m
/ mm
。 (Do you really expect to see "1:5 PM"?) I suspect just "dd-MM-yyyy H:mm tt"
should cover you. (你真的希望看到“下午1点5分”吗?)我怀疑只是"dd-MM-yyyy H:mm tt"
应该覆盖你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.