DateTime.Parse with the "+" symbol
.net, c#, datetime, iso8601
Solution
The only `+` in ISO8601 is in time offset part, and it looks like it is parsed this way in this case. But as far as I know all 3 parts of date required to have valid value before time offset is allowed.
I'd recommend using `DateTime.ParseExact(userInput,"yyyy-MM-dd",...` (maybe even with `InvariantCulture`).
`DateTime.Parse` accepts huge variety of inputs and tries to make best guess on users intentions. This feels like a case when it simply guesses in confusing way.
Sample values (first local PDT, 2 other with explicit time offset):
DateTime.Parse("1900-02" ).ToUniversalTime() // 2/ 1/1900 8:00:00 AM
DateTime.Parse("1900-02+00").ToUniversalTime() // 2/ 1/1900 12:00:00 AM
DateTime.Parse("1900-02+03").ToUniversalTime() // 1/31/1900 9:00:00 PM
Which seem that `Parse` essentially treats `"YYYY-MM+0x"` as `"YYYY-MM-01T00:00+0x"`.
Problem
I have a piece of code which parses and validates user input: ``` DateTime myDateTime = DateTime.Parse(userInput,currentCulture); ``` Current culture is being set (to en-ca or fr-ca) and the user Input is always in ISO 8601 format "yyyy-MM-dd". If the user enters 1900-01-01 the date is created as expected. If the input is "1900-01+01" the date time created is 1899-12-31 6:00:00 PM No exception is thrown, the DateTime.Parse happily converts this to the wrong date. To make this work I am using `DateTime.ParseExact(userInput,"yyyy-MM-dd",currentCulture)`. So my question is not how to make this work (I have that) but whats up with the +01 or any + value? Am I missing something in ISO standard?