Reputation: 165
My Date Format : 12/30/2014 12:00:00 AM (MM/dd/yyyy) and I have a string rep as
String DateOfIssue = "12/30/2014 12:00:00 AM";
DateTime DOI = DateTime.ParseExact((DateOfIssue).Trim(), "MM/dd/yyyy HH:mm:ss tt", CultureInfo.GetCultureInfo("en-GB"));
but it is throwing exception. I have seen a lot of posts on SO but none is working. What am I doing wrong ? Please help and point my error. I have tried en-US also but that is also not working.
when I remove tt
every thing works fine.
Upvotes: 2
Views: 1573
Reputation: 12618
HH
- is for 24 hours format, use hh
instead:
DateTime DOI = DateTime.ParseExact((DateOfIssue).Trim(), "MM/dd/yyyy hh:mm:ss tt", CultureInfo.GetCultureInfo("en-GB"));
Upvotes: 13