Reputation: 99
I want to convert a string : 24/11/2016 04:30 pm
to datetime value : 11/24/2016 04:30 pm
.
My code as :
DateTime date = DateTime.ParseExact("24/11/2016 04:30 pm", "dd/MM/yyyy hh:mm aa", CultureInfo.InvariantCulture);
But I get a error :
String was not recognized as a valid DateTime.
What can I do ?
Upvotes: 3
Views: 20286
Reputation: 460138
For the AM/PM designator you have to use tt
not aa
. Reading:
DateTime date = DateTime.ParseExact("24/11/2016 04:30 pm", "dd/MM/yyyy hh:mm tt", CultureInfo.InvariantCulture);
Upvotes: 14