Convert string to datetime

I am trying to convert a date string from one format to another. However, I am getting this exception error

The string was not recognized as a valid DateTime.

My code looks like this:

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 don't know what went wrong.

+3


source to share


1 answer


You must change

28-Feb-13 4:00:00 PM

before 28-Feb-13 04:00:00 PM



or

dd-MMM-yy hh:mm:ss tt

before dd-MMM-yy h:mm:ss tt

+13


source







All Articles