You can always force the format with DateTime.ParseExact
and avoid culture issues with using InvariantCulture
:
DateTime dt = DateTime.ParseExact("15-07-2013", "dd-MM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None);
Custom Date and Time Format Strings
However, your code works for me with culture "de-DE"
.
Update:
You have to use lower hh
for the hours when you provide the am/pm designator:
DateTime.ParseExact("15-07-2013 07:12:00 PM", "dd-MM-yyyy hh:mm:ss tt", CultureInfo.InvariantCulture, DateTimeStyles.None)
HH
means 24h format which makes no sense at all with the AM/PM designator.