472,358 Members | 1,880 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,358 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
Jul 21 '05 #1
8 2355
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

Jul 21 '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

Jul 21 '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
Jul 21 '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

Jul 21 '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
Jul 21 '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
Jul 21 '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

Jul 21 '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
Jul 21 '05 #9

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

Similar topics

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...
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...
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...
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

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.