473,411 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Culture and ShortDateFormat

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
3 2083
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: JezB | last post by:
How do I programatically set the culture at session level ?
0
by: Rob Dob | last post by:
Hi, I have a VS2003 C# asp.net project that has been converted into a VS2005 project. Everything seemed to work well until I make a modification to anything within the Component Designer...
3
by: shapper | last post by:
Hello, I am working on a multilanguage Asp.Net 2.0 web site. I need to do the following: 1. Set a default culture in Web.Config File. 2. Create a function which changes culture when pressed....
1
by: shapper | last post by:
Hello, I am initializing the culture of a page as follows: protected override void InitializeCulture() { base.InitializeCulture(); CultureInfo culture = Profile.Get().Visitor.Culture; if...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.