473,895 Members | 2,739 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

time format problem

Hi

I have changed my regional options on my computer to English (United States)
(I used to have Swedish). I would print the value of the current time in a
textbox on my asp.net page. I use this function:

txtTime.Text = DateTime.Now.To ShortTimeString ();

The time shown on the page is on the format 16:34 and I dont want that. I
want the american format. What can be wrong?

Thanks
Julia
Nov 23 '06 #1
5 2234
"Julia" wrote:
txtTime.Text = DateTime.Now.To ShortTimeString ();

The time shown on the page is on the format 16:34 and I dont want that. I
want the american format. What can be wrong?
Set the ShortTimePatter n property of the current culture thread:
http://msdn2.microsoft.com/en-us/lib...ng(VS.80).aspx
Nov 23 '06 #2
The code is run on the web server. If the server's regional setting is
Swedish, the text is still formatted in Swedish. It doesn't matter what
region the user is using.

If you want always display US format. You can
1) change the regional option of the server. or
2) format the time in us format (something like "hh:mm am/pm" but
not 100% sure). Or
3) sepcify the culture to get the time text.

John
Julia wrote:
Hi

I have changed my regional options on my computer to English (United States)
(I used to have Swedish). I would print the value of the current time in a
textbox on my asp.net page. I use this function:

txtTime.Text = DateTime.Now.To ShortTimeString ();

The time shown on the page is on the format 16:34 and I dont want that. I
want the american format. What can be wrong?

Thanks
Julia
Nov 23 '06 #3
Hi Julia,

That is odd. According to the .Net SDK regarding the return value of the
DateTime.ToShor TimeString method:

""The value of this instance is formatted using the short time format
character, 't'. The return value is identical to the value returned by
ToString ("t", null)."

This overload of the DateTime.ToStri ng method takes 2 parameters, the second
of which is a System.Globaliz ation.DateTimeF ormatInfo instance. If it is
null, the DateTimeFormatI nfo member of the static
System.Globaliz ationCurrentCul ture.CultureInf o property is used.

Again, according to the documentation, this Standard DateTime Format string
for the "en-us" culture specification is equivalent to the Custom DateTime
Format string "h:mm tt" (Hour 1-12, 2-digit Minute, and either "AM" or
"PM").

The CultureInfo.Cur rentCulture class is documented as, when a managed
Application Thread starts, the Windows API GetUserDefaultL CID function is
called, which obtains the Local Identifier from the Operating System. This
Local Identifier is what you would set in Control Panel if you changed your
Regional Options.

The only possibility I can guess is that, since an ASP.Net application is
hosted in IIS, if you changed your Regional Options and did not either
restart IIS or reboot the computer, the ASP.Net application may not have
restarted, and fetched the new Local Identifier.

Here are some references that should help:

http://msdn2.microsoft.com/en-us/lib...mepattern.aspx
http://msdn2.microsoft.com/en-us/lib...ltureinfo.aspx
http://msdn.microsoft.com/library/de...l/nls_08tg.asp
http://msdn.microsoft.com/library/de...l/nls_8sj7.asp

--
HTH,

Kevin Spencer
Microsoft MVP
Ministry of Software Development
http://unclechutney.blogspot.com

Never trust a dunderhead with a blunderbuss.
"Julia" <Ju***@discussi ons.microsoft.c omwrote in message
news:3D******** *************** ***********@mic rosoft.com...
Hi

I have changed my regional options on my computer to English (United
States)
(I used to have Swedish). I would print the value of the current time in a
textbox on my asp.net page. I use this function:

txtTime.Text = DateTime.Now.To ShortTimeString ();

The time shown on the page is on the format 16:34 and I dont want that. I
want the american format. What can be wrong?

Thanks
Julia

Nov 23 '06 #4
Hey Julia,

What you want to do is change the locale for the page to American
English just before you output the date.

So what you do is this:

System.Threadin g.Thread.Curren tThread.Current Culture = new
System.Globaliz ation.CultureIn fo("en-US");
txtTime.Text = DateTime.Now.To ShortTimeString ();

On Thu, 23 Nov 2006 07:40:02 -0800, Julia
<Ju***@discussi ons.microsoft.c omwrote:
>Hi

I have changed my regional options on my computer to English (United States)
(I used to have Swedish). I would print the value of the current time in a
textbox on my asp.net page. I use this function:

txtTime.Text = DateTime.Now.To ShortTimeString ();

The time shown on the page is on the format 16:34 and I dont want that. I
want the american format. What can be wrong?

Thanks
Julia
--

Bits.Bytes.
http://bytes.thinkersroom.com
Nov 23 '06 #5
Hi

and thanks for all the answers!

Finally I added these to my config file:

<globalizatio n
requestEncoding ="utf-8"
responseEncodin g="utf-8"
culture="en-US "
uiCulture="en-US "
/>
This section will force the application to use the american time format, so
this will solve my problem.

The strange thing is that I run everything on my local machine (iis, sql,
client) and I did change my regional options to English but still the format
was in Swedish. Maybe I didnt restart my computer so I will try that today.

Thanks
Julia

"Rad [Visual C# MVP]" wrote:
Hey Julia,

What you want to do is change the locale for the page to American
English just before you output the date.

So what you do is this:

System.Threadin g.Thread.Curren tThread.Current Culture = new
System.Globaliz ation.CultureIn fo("en-US");
txtTime.Text = DateTime.Now.To ShortTimeString ();

On Thu, 23 Nov 2006 07:40:02 -0800, Julia
<Ju***@discussi ons.microsoft.c omwrote:
Hi

I have changed my regional options on my computer to English (United States)
(I used to have Swedish). I would print the value of the current time in a
textbox on my asp.net page. I use this function:

txtTime.Text = DateTime.Now.To ShortTimeString ();

The time shown on the page is on the format 16:34 and I dont want that. I
want the american format. What can be wrong?

Thanks
Julia
--

Bits.Bytes.
http://bytes.thinkersroom.com
Nov 24 '06 #6

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

Similar topics

6
12967
by: David Graham | last post by:
Hi I have asked this question in alt.php as the time() function as used in setcookie belongs to php - or does it belong equally in the javascript camp - bit confused about that. Anyway, can anyone here put me straight on the following: I had a look at the time() function came across this: "To clarify, it seems this function returns the time of the computer's clock and does not do any timezone adjustments to return GMT, so you are...
7
8510
by: Edward Mitchell | last post by:
I have a number of DateTimePicker controls, some set to dates, some set to a format of Time. The controls are all embedded in dialogs. I created the controls by dragging the DateTime picker from the Toolbox and then set the Format property appropriately. I have noticed that sometimes the Time format will reset spontaneously to Short Date. I looked at the .rc file and found that the usual form for a Short Date is as follows: CONTROL ...
7
3029
by: Shimon Sim | last post by:
I have a custom composite control I have following property
10
1934
by: scorpion53061 | last post by:
What I thought would be pretty easy has turned out not to be. I have three variables. Actiontime is formatted as 08/11/2004 11:03PM Actiontime JobStreamStart (11:00:00PM) JobStreamEnd (2:00:00AM) If (Format(CDate(ActionTime), "t") >= JobStreamStart AND (Format(CDate(ActionTime), "t") < jobstreamend Then
1
4375
by: OleMacGeezer | last post by:
Hello Everyone, I am a brand new Python programmer with barely a month of experience under my belt. Here are my specs: Mac OSX Panther 10.3.9 Jython 2.1 implementation with Hermes BBS python module installed
0
9990
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
11250
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
10847
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
10938
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
10475
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8030
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...
1
4695
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
2
4291
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3298
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.