Culture and ShortDateFormat

Discussion in 'ASP .Net' started by =?Utf-8?B?SWFuIE8nUm91cmtl?=, May 6, 2004.

  1. 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.
    =?Utf-8?B?SWFuIE8nUm91cmtl?=, May 6, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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.
    Martin Dechev, May 6, 2004
    #2
    1. Advertising

  3. 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.
    =?Utf-8?B?SWFuIE8nUm91cmtl?=, May 7, 2004
    #3
  4. =?Utf-8?B?SWFuIE8nUm91cmtl?=

    Patrice Guest

    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" <> a écrit dans le message
    de news:...
    > 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.
    Patrice, May 7, 2004
    #4
    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. Mike Prager

    Culture and Codepage question

    Mike Prager, Aug 30, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    1,436
    Mike Prager
    Aug 30, 2003
  2. Bogdan POPESCU

    Culture and validators

    Bogdan POPESCU, Oct 24, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,419
  3. Ashish

    state server and thread culture

    Ashish, Mar 5, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    288
    Ashish
    Mar 5, 2004
  4. PL
    Replies:
    1
    Views:
    801
    Nicole Calinoiu
    Nov 9, 2005
  5. papaja

    Culture and date related problems

    papaja, Dec 2, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    381
    papaja
    Dec 2, 2005
Loading...

Share This Page