DateTime.ToString() outputting dates in US format on UK machine

N

Nick Gilbert

Hi,

One of our servers is behaving differently to all the others when
printing dates. They seem to be outputting in American format (12 hour)
when the default for a UK machine should be UK format (dd/mm/yyyy).

The following code:

DateTime.Now.ToString()
DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss")

...produces the following output:

5/10/2007 11:50:39 AM
10/05/2007 11:50:39 (correct)

On all other machines we have, both lines are the same as the second one
which is correct.

The settings in the control panel on the server are correct.

What's causing this discrepancy and how can I fix this? I seem to
remember something to do with a registry key or ASP.NET using the
settings of the console user by default. How can I force the machine
default to be UK settings?

Thanks,

Nick...
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Nick said:
Hi,

One of our servers is behaving differently to all the others when
printing dates. They seem to be outputting in American format (12 hour)
when the default for a UK machine should be UK format (dd/mm/yyyy).

The following code:

DateTime.Now.ToString()
DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss")

..produces the following output:

5/10/2007 11:50:39 AM
10/05/2007 11:50:39 (correct)

On all other machines we have, both lines are the same as the second one
which is correct.

The settings in the control panel on the server are correct.

What's causing this discrepancy and how can I fix this? I seem to
remember something to do with a registry key or ASP.NET using the
settings of the console user by default. How can I force the machine
default to be UK settings?

Thanks,

Nick...

My advice is to totally ignore the default setting of the server, and
create a CultureInfo object for the culture you want, or specify the
exact format that you want.

The culture settings in the control panel is unique for each user, but
on a server there may be more than one user logged in at once, and most
of the time there is no user logged in at all. IIS picks the culture
settings from some user account, but which account is used differs with
the version of the OS. Some version picks the settings from the last
logged in user, which means that if someone else logs in who has
different culture settings, the culture settings for all web sites
suddenly changes.
 
N

Nick Gilbert

The culture settings in the control panel is unique for each user, but
on a server there may be more than one user logged in at once, and most
of the time there is no user logged in at all. IIS picks the culture
settings from some user account, but which account is used differs with
the version of the OS. Some version picks the settings from the last
logged in user, which means that if someone else logs in who has
different culture settings, the culture settings for all web sites
suddenly changes.

I can see your point, but this would mean making extensive changes to
all affected websites hosted on this machine which could take days. I
would rather find out why this machine is defaulting to US settings when
all my other servers are OK.

I'm sure it's just a registry key change, but despite having spent ages
Googling, I can't seem to find it. I'm sure somebody must know what I'm
talking about and how to fix this.

Nick...
 
G

Guest

I can see your point, but this would mean making extensive changes to
all affected websites hosted on this machine which could take days. I
would rather find out why this machine is defaulting to US settings when
all my other servers are OK.

I'm sure it's just a registry key change, but despite having spent ages
Googling, I can't seem to find it. I'm sure somebody must know what I'm
talking about and how to fix this.

Nick...

Check if web.config has any settings in globalization key

and try to change

<globalization culture="en-GB" uiCulture="en-GB" />
 
N

Nick Gilbert

Check if web.config has any settings in globalization key
and try to change

<globalization culture="en-GB" uiCulture="en-GB" />

Great - this fixes the problem - thanks!

However it would still be nice if I could fix the underlying problem
that is causing this particular server to use US date setting by default.

Nick...
 
G

Guest

Great - this fixes the problem - thanks!

However it would still be nice if I could fix the underlying problem
that is causing this particular server to use US date setting by default.

Nick...

Check HKEY_USERS/.Default/Control Panel/International in the registry
and compare this section with the "right" server.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top