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

Discussion in 'ASP .Net' started by Nick Gilbert, May 10, 2007.

  1. Nick Gilbert

    Nick Gilbert Guest

    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...
     
    Nick Gilbert, May 10, 2007
    #1
    1. Advertising

  2. 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
     
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, May 10, 2007
    #2
    1. Advertising

  3. Nick Gilbert

    Nick Gilbert Guest

    > 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...
     
    Nick Gilbert, May 10, 2007
    #3
  4. On May 10, 6:34 pm, Nick Gilbert <> wrote:
    > > 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" />
     
    Alexey Smirnov, May 10, 2007
    #4
  5. Nick Gilbert

    Nick Gilbert Guest

    > 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...
     
    Nick Gilbert, May 11, 2007
    #5
  6. On May 11, 11:06 am, Nick Gilbert <> wrote:
    > > 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.
     
    Alexey Smirnov, May 11, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jimmy [Used-Disks]

    DateTime.ToString() format question

    Jimmy [Used-Disks], Sep 4, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    5,347
    Jimmy [Used-Disks]
    Sep 5, 2003
  2. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    868
    Rob Schieber
    Sep 30, 2005
  3. Grant Merwitz

    DateTime.ToString get specific time format

    Grant Merwitz, Mar 29, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    891
    Grant Merwitz
    Mar 30, 2007
  4. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    198
    Mark Schupp
    Aug 9, 2004
  5. Fergus McMenemie

    LibXML element->toString vs document->toString

    Fergus McMenemie, Jul 12, 2012, in forum: Perl Misc
    Replies:
    5
    Views:
    621
    Fergus McMenemie
    Jul 17, 2012
Loading...

Share This Page