CurrentCulture is ignored in DateTime.TryParse() when the date string is missing the year

560 Views Asked by At

Using the following code:

var value = "12-1";
DateTime dateTime;
var canParse = DateTime.TryParse(value, CultureInfo.CurrentCulture, DateTimeStyles.AssumeLocal, out dateTime);

The returned DateTime is the 1st of December of the current year. The current culture of my machine is {en-AU} and the date formats are set up for Australian formatted dates. When I hover over the CurrentCulture I can see that it is set to the en-AU culture.

I realise that the value is not a complete date but excel handles the same case. The TryParse method is returning a US formatted date when the date string is not fully specified.

Anything I can do?

0

There are 0 best solutions below