user2617750 user2617750 - 4 months ago 18
C# Question

Datetime.ParseExact "String was not recognized as a valid DateTime" error

Why i can't parse a string like this:

DateTime date = DateTime.ParseExact("‎23.‎02.‎2016 08:59:35",
"dd.MM.yyyy HH:mm:ss", CultureInfo.InvariantCulture);


It gives "String was not recognized as a valid DateTime" error.

I really don't understand.

Answer

There are some zero-width Unicode characters in your strings. If you remove them it will work:

DateTime.ParseExact("23.02.2016 08:59:35",
    "dd.MM.yyyy HH:mm:ss", CultureInfo.InvariantCulture)