According to Parsing Date and Time Strings (my emphasis):
The string representation of a date to be parsed must include the month and at least a day or year. The string representation of a time must include the hour and at least minutes or the AM/PM designator. However, parsing supplies default values for omitted components if possible. A missing date defaults to the current date, a missing year defaults to the current year, a missing day of the month defaults to the first day of the month, and a missing time defaults to midnight.
Unfortunately, this doesn't seem to work ideally when using other locales. For example, using nb-NO
, my WPF DatePicker formats dates as 31.12.2017
, and I want the string 1.2
to be parsed as February 1st of the current year. However, it's interpreted as the time 01.02.00
and today's date is used instead with the parsed time. (The parsing works as desired if I write 1/2
, but I don't want to force users to use non-default separators for their locale.)
Is there any way to make use of .NET's built-in locale-aware date parsing, but force it to only parse the date, not time? (I can't use ParseExact
because I need to support different locales; therefore, these questions aren't helpful.)