Culture and ShortDateFormat

G

Guest

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.
 
M

Martin Dechev

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.InvariantInfo)

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 said:
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.
 
G

Guest

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.
 
P

Patrice

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 said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top