473,698 Members | 2,410 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 programmaticall y

Sub Application_Beg inRequest(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.Cur rent.Request.Us erLanguages(0
culture = CultureInfo.Cre ateSpecificCult ure(lang
Thread.CurrentT hread.CurrentCu lture = 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 2095
Hi, Ian O'Rourke,

What is the value of HttpContext.Cur rent.Request.Us erLanguages(0)? I'm quite
sure it's "en" if you're getting M/dd/yyy for the ShortDatePatter n.

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.ParseE xact("25/12/2004", "dd/MM/yyyy", _
System.Globaliz ation.DateTimeF ormatInfo.Invar iantInfo)

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*******@disc ussions.microso ft.com> wrote in message
news:86******** *************** ***********@mic rosoft.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 programmaticall y:

Sub Application_Beg inRequest(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.Cur rent.Request.Us erLanguages(0)
culture = CultureInfo.Cre ateSpecificCult ure(lang)
Thread.CurrentT hread.CurrentCu lture = 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*******@disc ussions.microso ft.com> a écrit dans le message
de news:2F******** *************** ***********@mic rosoft.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
599
by: JezB | last post by:
How do I programatically set the culture at session level ?
0
9164
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 window, i.e. I add a SQLCommand. At that point VS2005 changes my C# file to now load all Selectcommantext data from the resource file instead of the .aspx.cs file. then when I try and once again run my application I get the following error: looking...
3
3380
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. Remember the choosen culture next time the visitor comes to the web site. 3. Retrieve the current culture.
1
1537
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 (culture == null) culture = default(CultureInfo); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture;
0
8676
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9164
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8898
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7734
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6524
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3051
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.