将字符串转换为datetime问题

时间:2013-02-15 07:27:45

标签: c#

我正在尝试将一种格式的日期字符串转换为另一种格式。但是,我收到此异常错误消息

  

字符串未被识别为有效的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");

我真的不知道出了什么问题。

1 个答案:

答案 0 :(得分:13)

你必须改变

28-Feb-13 4:00:00 PM28-Feb-13 04:00:00 PM

dd-MMM-yy hh:mm:ss ttdd-MMM-yy h:mm:ss tt