Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Culture and ShortDateFormat

Reply
Thread Tools

Culture and ShortDateFormat

 
 
=?Utf-8?B?SWFuIE8nUm91cmtl?=
Guest
Posts: n/a
 
      05-06-2004
Okay, I have a problem with the en-GB culture object

My computer is set to the UK and for UK date formats, etc

If I set my culture to en-GB in the web.config everything works fine with UK dates

If I set my culture programmatically

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs
' Fires at the beginning of each reques

Dim culture As CultureInf
Dim lang As Strin

lang = HttpContext.Current.Request.UserLanguages(0
culture = CultureInfo.CreateSpecificCulture(lang
Thread.CurrentThread.CurrentCulture = cultur

End Su

I find I cannot enter dates in the UK format - it expects the US format. On investigating I found the reason why, when browsing the culture object created in the code its shortdateformat property is set to M/dd/yyyy which is incorrect

If the culture is set to US or FR via the above code the shortdateformat property is set fine and as a result everything works

I'm not totally confused as you get the culture objects from the Framework, no? So I seem to be in an unfixable situation at the moment.
 
Reply With Quote
 
 
 
 
Martin Dechev
Guest
Posts: n/a
 
      05-06-2004
Hi, Ian O'Rourke,

What is the value of HttpContext.Current.Request.UserLanguages(0)? I'm quite
sure it's "en" if you're getting M/dd/yyy for the ShortDatePattern.

Solutions:

Option 1 is to check the value and change it to "en-GB" if it is something
you don't expect/want.

Option 2 is to parse the dates using the static (shared) method ParseExact
on the DateTime structure. For displaying - you can use the overload of the
instance method ToString on the DateTime structure that takes the pattern as
string parameter. eg:

Dim d as DateTime = _
DateTime.ParseExact("25/12/2004", "dd/MM/yyyy", _
System.Globalization.DateTimeFormatInfo.InvariantI nfo)

Dim s As String = d.ToString("dd/MM/yyyy")

Maybe there are more options, but these are the first to come to my mind.

Hope this helps
Martin
"Ian O'Rourke" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Okay, I have a problem with the en-GB culture object.
>
> My computer is set to the UK and for UK date formats, etc.
>
> If I set my culture to en-GB in the web.config everything works fine with

UK dates.
>
> If I set my culture programmatically:
>
> Sub Application_BeginRequest(ByVal sender As Object, ByVal e As

EventArgs)
> ' Fires at the beginning of each request
>
> Dim culture As CultureInfo
> Dim lang As String
>
> lang = HttpContext.Current.Request.UserLanguages(0)
> culture = CultureInfo.CreateSpecificCulture(lang)
> Thread.CurrentThread.CurrentCulture = culture
>
> End Sub
>
> I find I cannot enter dates in the UK format - it expects the US format.

On investigating I found the reason why, when browsing the culture object
created in the code its shortdateformat property is set to M/dd/yyyy which
is incorrect?
>
> If the culture is set to US or FR via the above code the shortdateformat

property is set fine and as a result everything works.
>
> I'm not totally confused as you get the culture objects from the

Framework, no? So I seem to be in an unfixable situation at the moment.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SWFuIE8nUm91cmtl?=
Guest
Posts: n/a
 
      05-07-2004
It is coming back as en-g

I can set the culture with a literal string of en-GB and it still gets the shortdateformat wrong when I browse the object

As I say, when I set it to en-GB in the web.config it works fine.
 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      05-07-2004
What if you start by changing this in an ASPX page ? What if you read back
the culture ? Is this the gb culture with the bad information or is the
culture left unchanged despite your change ?

Patrice

"Ian O'Rourke" <(E-Mail Removed)> a écrit dans le message
de news:(E-Mail Removed)...
> It is coming back as en-gb
>
> I can set the culture with a literal string of en-GB and it still gets the

shortdateformat wrong when I browse the object.
>
> As I say, when I set it to en-GB in the web.config it works fine.



 
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
[MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture. Rob Dob ASP .Net Web Controls 0 11-27-2005 03:57 PM
[MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture. Rob Dob ASP .Net 0 11-27-2005 03:57 PM
state server and thread culture Ashish ASP .Net 0 03-05-2004 11:55 PM
Culture and validators Bogdan POPESCU ASP .Net 1 10-24-2003 11:54 AM
Culture and Codepage question Mike Prager ASP .Net 2 08-30-2003 07:22 PM



Advertisments