[英]Convert string to datetime issue
I'm trying to convert a date string in one format into another. 我正在尝试将一种格式的日期字符串转换为另一种格式。 However, I get this exception error message
但是,我收到此异常错误消息
String was not recognized as a valid DateTime.
字符串未被识别为有效的DateTime。
My code is as follows: 我的代码如下:
string theDate = "28-Feb-13 4:00:00 PM";
DateTime tempDate = DateTime.ParseExact(theDate, "dd-MMM-yy hh:mm:ss tt", CultureInfo.InvariantCulture, DateTimeStyles.None);
convertedDate = tempDate.ToString("yyyy/MM/dd hh:mm:ss");
I seriously have no idea what went wrong. 我真不知道出了什么问题。
You must change 你必须改变
28-Feb-13 4:00:00 PM
to 28-Feb-13 04:00:00 PM
28-Feb-13 4:00:00 PM
至28-Feb-13 04:00:00 PM
or 要么
dd-MMM-yy hh:mm:ss tt
to dd-MMM-yy h:mm:ss tt
dd-MMM-yy hh:mm:ss tt
to dd-MMM-yy h:mm:ss tt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.