Now() Fucntion and CurrentCulture

Discussion in 'ASP .Net' started by ra294, Nov 25, 2004.

  1. ra294

    ra294 Guest

    When I use the Now() Fucntion i my ASP.net application I get a date format
    of mm/dd/yy.
    I want it to be dd/mm/yy. I set in the web config "culture="en-GB"
    uiCulture="en" and also set the regional setting of the computer.
    When I am checking "Thread.CurrentThread.CurrentCulture" I can see it's
    "en-GB" and the date format is like I want it (dd/mm/yy), but still the
    Now() function gives me mm/dd/yy format.
    How do I correct this problem ?

    Thanks

     
    ra294, Nov 25, 2004
    #1
    1. Advertising

  2. I think you have to set CurrentUICulture:
    Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;


    "ra294" <> wrote in message
    news:%...
    > When I use the Now() Fucntion i my ASP.net application I get a date format
    > of mm/dd/yy.
    > I want it to be dd/mm/yy. I set in the web config "culture="en-GB"
    > uiCulture="en" and also set the regional setting of the computer.
    > When I am checking "Thread.CurrentThread.CurrentCulture" I can see it's
    > "en-GB" and the date format is like I want it (dd/mm/yy), but still the
    > Now() function gives me mm/dd/yy format.
    > How do I correct this problem ?
    >
    > Thanks
    >
    >
    >
    >
     
    Eirik Eldorsen, Nov 25, 2004
    #2
    1. Advertising

  3. ra294

    Hans Kesting Guest

    ra294 wrote:
    > When I use the Now() Fucntion i my ASP.net application I get a date
    > format of mm/dd/yy.
    > I want it to be dd/mm/yy. I set in the web config "culture="en-GB"
    > uiCulture="en" and also set the regional setting of the computer.
    > When I am checking "Thread.CurrentThread.CurrentCulture" I can see
    > it's "en-GB" and the date format is like I want it (dd/mm/yy), but
    > still the Now() function gives me mm/dd/yy format.
    > How do I correct this problem ?
    >
    > Thanks
    >
    >


    DateTime.Now doesn't give a "mm/dd/yyyy" string, it gives a DateTime value.
    When you do a ToString() on that DateTime value, you might get
    a "mm/dd/yyyy" string. The debugger also shows the result of ToString().

    You might try setting the CurrentUICulture, but in this particular case
    there is another option: use ToString("dd/MM/yyyy") (use capital MM
    to get month, lowercase mm returns minutes)

    By the way, if you are only interested in the date, you can also use
    DateTime.Today.


    Hans Kesting
     
    Hans Kesting, Nov 25, 2004
    #3
  4. Put this code in Application_BeginRequest event (global.asax)
    Normally the ToString() function displays a string based on the current
    culture.
    So you must change current culture.

    Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture
    = new CultureInfo("en-GB");


    Hope this helps!
    Franck Quintana.
     
    Franck Quintana, Nov 25, 2004
    #4
  5. ra294

    ra294 Guest

    I tried both setting the CurrentUICulture and also
    Now.ToString("dd/MM/yyyy") and I still get mm/dd/yyyy format when using the
    Now() function.

    Any other ideas ?



    "Franck Quintana" <> wrote in message
    news:41a5fb12$0$3521$...
    > Put this code in Application_BeginRequest event (global.asax)
    > Normally the ToString() function displays a string based on the current
    > culture.
    > So you must change current culture.
    >
    > Thread.CurrentThread.CurrentCulture =
    > Thread.CurrentThread.CurrentUICulture
    > = new CultureInfo("en-GB");
    >
    >
    > Hope this helps!
    > Franck Quintana.
    >
     
    ra294, Nov 25, 2004
    #5
  6. ra294

    Hans Kesting Guest

    ra294 wrote:
    > I tried both setting the CurrentUICulture and also
    > Now.ToString("dd/MM/yyyy") and I still get mm/dd/yyyy format when
    > using the Now() function.
    >
    > Any other ideas ?
    >


    *Where* do you get that mm/dd/yyyy format? In the debugger-window?
    The Now.ToString("dd/MM/yyyy") returns a formatted string, it doesn't *set*
    the format "to use from now on". A following call to Now() returns a new DateTime
    value and if you have this converted to string (as vb probably does automatically)
    you are really calling the ToString() method with no parameters, so you get
    the default US format of mm/dd/yyyy.

    Hans Kesting
     
    Hans Kesting, Nov 26, 2004
    #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. Clive
    Replies:
    1
    Views:
    666
    Sherif ElMetainy
    Aug 28, 2003
  2. magister
    Replies:
    12
    Views:
    10,645
    anukadevkizm
    Jan 5, 2007
  3. DZoid
    Replies:
    1
    Views:
    2,369
    Karl Seguin
    Sep 24, 2004
  4. 00_CumPeeWearD12

    CurrentCulture null in release

    00_CumPeeWearD12, Feb 6, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    345
    00_CumPeeWearD12
    Feb 6, 2005
  5. 00_CumPeeWearD12

    CurrentCulture null in release

    00_CumPeeWearD12, Feb 6, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    359
    00_CumPeeWearD12
    Feb 6, 2005
Loading...

Share This Page