DateTime.Parse() is locale sensitive
The DateTime.Parse() method (and all its derivatives, i assume) are locale sensitive and will assume that the string you provide it is in the standard ISO date format, or in the format for your locale.
The buggy implementation I found in our system was calling DateTime.Parse() with a value of “23-07-2007″, which threw an exception citing that the string was not in the correct format. I dug around a bit with the code and tried different implementations with different results. It was only after i provided it a US date value (which it did not baulk at) I realised that my system’s locale was set to English (US).
The code was wrong to assume the current system locale is the expected input data format, in the first place, but this one tripped me up for a little while.
Related posts:
- Making Assumptions About An Objects State I’ve seen this now twice in about 30 mins, and...
- Happy Birthday (The C-Sharp way) This evening I wanted to wish someone a happy birthday....
- Thread Safety and Locking I was recently reading a post about writing non-threadsafe code...
- A Programming Job Interview Challenge #13 – Brackets As the title suggests, here is my solution for A...
- MCMS: GetByGuid throws COMException (“Server Error”) In (the now famous) Project P, working with Microsoft CMS’s...