3

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.

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.

4

1 回答 1

13

You must change

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

or

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

于 2013-02-15T07:30:23.833 回答