我正在尝试将一种格式的日期字符串转换为另一种格式。但是,我收到此异常错误消息
字符串未被识别为有效的DateTime。
我的代码如下:
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");
我真的不知道出了什么问题。
答案 0 :(得分:13)
你必须改变
28-Feb-13 4:00:00 PM
至28-Feb-13 04:00:00 PM
或
dd-MMM-yy hh:mm:ss tt
至dd-MMM-yy h:mm:ss tt