DateTime & ToShortDateString

  • Thread starter Thread starter Nugnet
  • Start date Start date
N

Nugnet

Hi,
I have an ASP.NET web application that I want to be locale sensitive. I
set my regional options to be English (United States) and rebooted my
machine (normally have English(United Kingdom setting)).
I then ran the web app and on a page where I wanted to display a
default date of the current date, I had a call to
DateTime.ToShortDateString().
The date that was displayed on the page still used the English (United
Kingdom) date format (i.e. dd/mm/yyyy).
Is there some other setting required in ASP.NET to display the current
locales date format. I wrote a small app to display the CurrentLocale
and CurrentUILocale and they both were English (United States).

Thank you in advance for any help
John
 
Nugnet said:
I have an ASP.NET web application that I want to be locale sensitive. I
set my regional options to be English (United States) and rebooted my
machine (normally have English(United Kingdom setting)).
I then ran the web app and on a page where I wanted to display a
default date of the current date, I had a call to
DateTime.ToShortDateString().
The date that was displayed on the page still used the English (United
Kingdom) date format (i.e. dd/mm/yyyy).
Is there some other setting required in ASP.NET to display the current
locales date format. I wrote a small app to display the CurrentLocale
and CurrentUILocale and they both were English (United States).

Ah, but was your app a web app? I suspect that the web app is adjusting
to the locale of the *browser*, not of the system.

Try changing your browser's preferences to tell *that* that you're in
the US.
 
Jon said:
Ah, but was your app a web app? I suspect that the web app is adjusting
to the locale of the *browser*, not of the system.

Try changing your browser's preferences to tell *that* that you're in
the US.

Is that possible? How does that work? I used to think that in ASP.NET,
because the code (specifically DateTime.ToShortDateString()) is getting
executed on the server, it should use the preferences configured in the
server. Am I missing something here?
 
Jonas Hei said:
Is that possible? How does that work? I used to think that in ASP.NET,
because the code (specifically DateTime.ToShortDateString()) is getting
executed on the server, it should use the preferences configured in the
server. Am I missing something here?

Yes - the fact that the browser provides its list of language
preferences, and I believe that ASP.NET will change either the
CurrentCulture or CurrentUICulture of the thread handling the request
to the preferred locale of the browser for the duration of the request.
It's easy enough to check though - just make a web app write out both
of those cultures, and try changing your preferred culture in your
browser.
 
Back
Top