By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

Culture and ShortDateFormat

P: n/a
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.
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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" <an*******@discussions.microsoft.com> wrote in message
news:86**********************************@microsof t.com...
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.

Nov 18 '05 #2

P: n/a
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.
Nov 18 '05 #3

P: n/a
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" <an*******@discussions.microsoft.com> a écrit dans le message
de news:2F**********************************@microsof t.com...
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.

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.