473,386 Members | 1,819 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,386 software developers and data experts.

How To: Work around a Users Region Setting (Date issue)???

My PC's Region setting is set to "English (Canada)"... cause I am in Canada
(eh?) (: I'm using VB.net, standard edition (v1?)

So I wrote my application based on this Region. I've both Short and Long
dates being displayed (including a DateTimePicker).

BUT... at work, there are some machines which the Region is the ol' default of
"English (United States)".

Canadian:
Short = dd/MM/yy
Long = MMMM d, yyyy

USA:
Short = M/d/yyy
Long = dddd, MMMM dd, yyyy

What my issue is is that my Date displays (both for long and short) are either
OK or Screwed up depending upon the Region display. This because my labels,
textboxes, etc. have 'fixed' widths.

Bah! Changing the PC's Regions is NOT an option (I won't go into that).

So how can I have my app display what I want?

I know I can 'build' the date string. Such for a Label, I can have:
myMonth & myDay & myYear... etc.

But the DateTimePicker is got me stumped.

Prefferably, there must be an easier way to do this so that 'globally' my app
works for English (Canadian) and not screw up the Users PC Region setting.

Thanks

James
Nov 20 '05 #1
8 1200
Why don't you use Formatting?

1. String.Format("mmDDyyyy",myDate)
2. myDate.ToString("mmDDyyyy")

Remember that month should be DD and not dd. I have done that once before
and was writing minutes instead of months!! Bad eh? This is case sensitive.
Mind you I believe it is a by-design bug. ;-)
"JamesBV" <No****@telus.net> wrote in message
news:ov********************************@4ax.com...
My PC's Region setting is set to "English (Canada)"... cause I am in Canada (eh?) (: I'm using VB.net, standard edition (v1?)

So I wrote my application based on this Region. I've both Short and Long
dates being displayed (including a DateTimePicker).

BUT... at work, there are some machines which the Region is the ol' default of "English (United States)".

Canadian:
Short = dd/MM/yy
Long = MMMM d, yyyy

USA:
Short = M/d/yyy
Long = dddd, MMMM dd, yyyy

What my issue is is that my Date displays (both for long and short) are either OK or Screwed up depending upon the Region display. This because my labels, textboxes, etc. have 'fixed' widths.

Bah! Changing the PC's Regions is NOT an option (I won't go into that).

So how can I have my app display what I want?

I know I can 'build' the date string. Such for a Label, I can have:
myMonth & myDay & myYear... etc.

But the DateTimePicker is got me stumped.

Prefferably, there must be an easier way to do this so that 'globally' my app works for English (Canadian) and not screw up the Users PC Region setting.

Thanks

James

Nov 20 '05 #2
You can manually set the current thread's UI Culture to whatever you want.
System.Threading.CurrentUICulture (something around there).
-mike
MVP

"JamesBV" <No****@telus.net> wrote in message
news:ov********************************@4ax.com...
My PC's Region setting is set to "English (Canada)"... cause I am in Canada (eh?) (: I'm using VB.net, standard edition (v1?)

So I wrote my application based on this Region. I've both Short and Long
dates being displayed (including a DateTimePicker).

BUT... at work, there are some machines which the Region is the ol' default of "English (United States)".

Canadian:
Short = dd/MM/yy
Long = MMMM d, yyyy

USA:
Short = M/d/yyy
Long = dddd, MMMM dd, yyyy

What my issue is is that my Date displays (both for long and short) are either OK or Screwed up depending upon the Region display. This because my labels, textboxes, etc. have 'fixed' widths.

Bah! Changing the PC's Regions is NOT an option (I won't go into that).

So how can I have my app display what I want?

I know I can 'build' the date string. Such for a Label, I can have:
myMonth & myDay & myYear... etc.

But the DateTimePicker is got me stumped.

Prefferably, there must be an easier way to do this so that 'globally' my app works for English (Canadian) and not screw up the Users PC Region setting.

Thanks

James

Nov 20 '05 #3
Why don't you use Formatting?

1. String.Format("mmDDyyyy",myDate)
2. myDate.ToString("mmDDyyyy")


Hmmmm... okay. But will this allow me to change the DateTimePicker display?
I'm not sure if it will.

I changed my Region Date to USA standard.

I then tried putting MMMM d, yyyy in the Properties "Custom Format" line...
and then changed the "Format" line to 'Custom'. But the display still showed
USA format.

Other than that... the other stuff (labels, textboxes) work fine.

Idea?

Thanks.

James
Nov 20 '05 #4
James,

DateTimePicker is one of those dodgy controls (e.g you cannnot set
background colour for the text) and I am not surprised if it behaves badly.
But, I tested that on my machine (UK setting) with "MMMM d, yyyy" in format
property and setting the format to custom and it did show "November 12,
2003". Are you trying to use "Value" property in code? I am using VB.NET
2003 and that might cause the difference (very unlikely though)

Michael's approach is very professional and polished (he is MVP after all
;-)):
System.Threading.Thread.CurrentThread.CurrentUICul ture = New
System.Globalization.CultureInfo("en-CA")

You might as well use that.

Cheers
Ali


"JamesBV" <No****@telus.net> wrote in message
news:0u********************************@4ax.com...
Why don't you use Formatting?

1. String.Format("mmDDyyyy",myDate)
2. myDate.ToString("mmDDyyyy")
Hmmmm... okay. But will this allow me to change the DateTimePicker

display? I'm not sure if it will.

I changed my Region Date to USA standard.

I then tried putting MMMM d, yyyy in the Properties "Custom Format" line... and then changed the "Format" line to 'Custom'. But the display still showed USA format.

Other than that... the other stuff (labels, textboxes) work fine.

Idea?

Thanks.

James

Nov 20 '05 #5
background colour for the text) and I am not surprised if it behaves badly.
But, I tested that on my machine (UK setting) with "MMMM d, yyyy" in format
I don't know what I did.. but just before finding this 2nd reply of yours. I
got it to work!! Must have done something wrong the first time. (sigh)
Michael's approach is very professional and polished (he is MVP after all
;-)):
System.Threading.Thread.CurrentThread.CurrentUICu lture = New
System.Globalization.CultureInfo("en-CA")


True. Where does this go? In Form Load? I placed it there but nothing
happened. Obviously this needs more work.

Thanks!

James
Nov 20 '05 #6
You can manually set the current thread's UI Culture to whatever you want.
System.Threading.CurrentUICulture (something around there).


Alireza gave me the following:

System.Threading.Thread.CurrentThread.CurrentUICul ture = New
System.Globalization.CultureInfo("en-CA")

Just got to place it, use it properly (of which I have no idea... never have
had the 'pleasure' of Threading before) (:

Thanks!

James
Nov 20 '05 #7
If you want your whole app to be in a certain culture, you can set the
thread's culture on startup of your app and leave it.

If it's only for a particular piece of code, then you should save the
original culture, set the new one, then revert when you are done using it.

The *real way* is to figure out how to make your app respond correctly no
matter what culture it's running on. Manual override is a hackish solution.
But if it's just for an internal system that doesn't have international
requirments, it *probably* won't matter (unless some VP from Korea comes
over and runs it and it crashes ;)).

-mike
MVP

"JamesBV" <No****@telus.net> wrote in message
news:je********************************@4ax.com...
You can manually set the current thread's UI Culture to whatever you want.System.Threading.CurrentUICulture (something around there).
Alireza gave me the following:

System.Threading.Thread.CurrentThread.CurrentUICul ture = New
System.Globalization.CultureInfo("en-CA")

Just got to place it, use it properly (of which I have no idea... never

have had the 'pleasure' of Threading before) (:

Thanks!

James

Nov 20 '05 #8
If you want your whole app to be in a certain culture, you can set the
thread's culture on startup of your app and leave it.
Actually it is only for work here in Canada. I just wanted to overcome the
PC's which have the USA date/time Region setting because I did my code based
on my PC (being Canadian Region setting).
requirments, it *probably* won't matter (unless some VP from Korea comes
over and runs it and it crashes ;)).


LOL...

What I ended up doing (because it only affected 5 lines) was to 'force' the
Code Format. Tried it with both Regions set for my PC and I think I've got it
licked.

But it would have been nicer (of course) to have set it in one spot. Maybe in
the future when I go International (:

Thanks again for your Time!

James
Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: JamesBV | last post by:
My PC's Region setting is set to "English (Canada)"... cause I am in Canada (eh?) (: I'm using VB.net, standard edition (v1?) So I wrote my application based on this Region. I've both Short...
4
by: BBFrost | last post by:
We have a data entry application written within Framework 1.0 that contains 20+ custom user controls. The controls overlay each other so that only one custom control is visible at a time. What...
5
by: fbwhite | last post by:
I know this issue has been brought up many times, but I have tried many of the solutions to no avail. I wanted to give my specific case to see if someone could be of any help. We are using the...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
5
by: Oleg Subachev | last post by:
Are there good classes to work with .INI-files from C# ? Oleg Subachev
0
by: Steve | last post by:
To begin, I'm using Adobe's Spry Framework for all my data in my XML page, it saves space and code on the HTML. Well, I want to make it so that certain cells are chosen and are either highlighted...
14
by: Zhang Weiwu | last post by:
Hello. I have been using word processor like OOO for nearly 10 years and such layout is very usual to me: gopher://sdf.lonestar.org/I/users/weiwu/ooo_wrap_correctly.png but I found it's very...
9
by: =?Utf-8?B?Sm9obiBCYWlsZXk=?= | last post by:
I have a ASP .Net page that allows moving around items on the page through javascript. This page works fine in IE. In FireFox however, I have found that if the page is using XHTML 1.0...
6
by: Kelii | last post by:
Hello, So I have a form which shows all items available for sale, when it was last sold, where it was last sold, and whether it is active or inactive. I would like to be able to edit the...
3
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
Note: My apologies for repeating this post from last week, but my nospam alias and profile account were incorrect. I think I have fixed this, so hopefully this post will trigger MS into a response...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.