Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Now() Fucntion and CurrentCulture

Reply
Thread Tools

Now() Fucntion and CurrentCulture

 
 
ra294
Guest
Posts: n/a
 
      11-25-2004
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




 
Reply With Quote
 
 
 
 
Eirik Eldorsen
Guest
Posts: n/a
 
      11-25-2004
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
>
>
>
>



 
Reply With Quote
 
 
 
 
Hans Kesting
Guest
Posts: n/a
 
      11-25-2004
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


 
Reply With Quote
 
Franck Quintana
Guest
Posts: n/a
 
      11-25-2004
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.

 
Reply With Quote
 
ra294
Guest
Posts: n/a
 
      11-25-2004
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.
>



 
Reply With Quote
 
Hans Kesting
Guest
Posts: n/a
 
      11-26-2004
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regional Settings en-GB CultureInfo.CurrentCulture.Name = en-US magister ASP .Net 12 01-05-2007 03:41 PM
CurrentCulture null in release 00_CumPeeWearD12 ASP .Net 0 02-06-2005 10:21 PM
CurrentCulture null in release 00_CumPeeWearD12 ASP .Net 0 02-06-2005 10:20 PM
CurrentCulture, CurrentUICulture and Threads DZoid ASP .Net 1 09-24-2004 08:07 PM
Thread.CurrentThread.CurrentCulture Clive ASP .Net 1 08-28-2003 05:21 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57