473,406 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

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...
May 10 '07 #1
5 3607
Nick Gilbert wrote:
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.

--
Göran Andersson
_____
http://www.guffa.com
May 10 '07 #2
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...
May 10 '07 #3
On May 10, 6:34 pm, Nick Gilbert <n...@newsgroup.nospamwrote:
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...
Check if web.config has any settings in globalization key

and try to change

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

May 10 '07 #4
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...
May 11 '07 #5
On May 11, 11:06 am, Nick Gilbert <n...@newsgroup.nospamwrote:
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...
Check HKEY_USERS/.Default/Control Panel/International in the registry
and compare this section with the "right" server.

May 11 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
by: nobody | last post by:
I know that given a FormatString and a DateTime you can use DateTime.ToString(...) to convert the DateTime to a String. My question is how can you turn that around? Given a String and a...
5
by: ns21 | last post by:
Our application is windows desktop application. We are using VS.Net 2003, C#, Framework 1.1, SQL 2000. We use webservices to add/update/select objects. We are using XML Serialization. Following is...
9
by: Simon Harvey | last post by:
Hi all, I'm having a bit of a problem working with dates. My computer is british, but I'm developing an american application so I therefore need to use american dates. But I can't get my...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.