[英]Convert Date String to DateTime
I have to convert a date string to a DateTime object as follows我必须将日期字符串转换为 DateTime object,如下所示
tmpdate = "27-Apr 14:53";
TheDate = DateTime.ParseExact(tmpdate, "DD-MMM HH:mm", CultureInfo.InvariantCulture);
I keep getting exceptions about the string not being a valid date time.我不断收到关于字符串不是有效日期时间的异常。 I've tried adding in the year as well with no luck.
我也尝试在这一年添加,但没有运气。 Any suggestions?
有什么建议么?
Try dd-MMM HH:mm
- note lowercased dd
.试试
dd-MMM HH:mm
- 注意小写的dd
。
try with little d:尝试小d:
TheDate = DateTime.ParseExact(tmpdate, "dd-MMM HH:mm", CultureInfo.InvariantCulture);
string tmpdate = "27-Apr 14:53";
DateTime TheDate = DateTime.ParseExact(tmpdate, "dd-MMM HH:mm", System.Globalization.CultureInfo.InvariantCulture);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.