I converted my VS 2008 project into vs 2010 but kept it on .NET 3.5 framework. I don’t set my locale anywhere within the app.
I’ve got a couple on computers running windows 7 and XP and both have the region set to EN-AU.
Sometime my app returns the short date format like MM/dd/YY (EN-US). As soon as you quit it and start again it reverts to the proper format for AU(dd/mm/yy). Again I’m not setting my locale anywhere in the project. (I have some RDLC reports which have EN-US as the language though)
Any reason why this would be happening? I tried setting the Thread locale explicitly as well. But same behaviour.
This is strange.
I would advice you not to use ToShortDate() as I have seen couple of issues from it. Instead, I recommend using following code:
string formattedDate = someDateTime.ToString(“d”, CultureInfo.CurrentCulture);
This basically does the same. And you can introduce constant instead of “d” for greater readability (it is short date formatting string).
It is always good practice to pass IFormatProvider, as it works as a comment clearly documenting your assumptions (in the example above I said: this is the date string I want to present to user; if I wanted to use this date for further processing, send it via network, etc. I would use CultureInfo.InvariantCulture).