Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How convert string to Datetime by a format? [duplicate]

Possible Duplicate:
Convert string to DateTime in c#

How can I convert string to DateTime by a format?

Convert.ToDateTime("12/11/17 2:52:35 PM")

Result is 12/11/2017 02:52:35 PM and this is incorrect because my expect is 11/17/2012 02:52:35 PM

like image 850
Ehsan Avatar asked Dec 31 '12 16:12

Ehsan


1 Answers

You're looking for DateTime.ParseExact().

DateTime.ParseExact(myStr, "yy/MM/dd h:mm:ss tt", CultureInfo.InvariantCulture);
like image 116
SLaks Avatar answered Sep 20 '22 13:09

SLaks