I am observing some strange behavior in case of DateTime.ParseExact method with the Swedish (sv-SE) culture.
My computer’s culture is en-US but the business logic demands the sv-SE culture. So I set it on the current thread first.
Thread.CurrentThread.CurrentUICulture = new CultureInfo("sv-SE");
Then I do the following to parse the DateTime value. The datetime I am trying to parse here is 11:57 AM on 27th May 2012.
DateTime.ParseExact("270512T11:57", "ddMMyyThh:mm", Thread.CurrentThread.CurrentUICulture);
This works just fine.
But I get the exception when the time is from the night. When I try to parse the datetime stamp of value 11:57 PM on 27th May 2012.
DateTime.ParseExact("270512T23:57", "ddMMyyThh:mm", Thread.CurrentThread.CurrentUICulture);
The above line gives the FormatException with the message String was not recognized as a valid DateTime..
What is really wrong here?
hh is 12-hour clock only. If you change your format string to “ddMMyyTHH:mm” it should work.