Select Categories Below
Status: Closed Points: 75 Time: 15:45 - Jul 11, 2006
dustPuppy
How do I set the timezone in my asp.net application? The problem is that the server is in a different timezone, so everything is registered a few hours earlier than the actual time that I'm using. I supposed it was through the CultureInfo, but I can't find anywhere to set it. I'm using ASP.NET 1.1 and C#.
Categories:
Add Categories
When adding more than one category, separate them with commas.
Advertisement
PeterNZ
Date:: Jul 11, 2006
Time:: 22:14
Simple answer: You can't! The CultureInfo you are referring to and the CultureUI class is used to set formats only. I.e. if you set CultureUI to en-GB it will show all numbers, dates etc in UK English format. It does not reflect the timezone i.e. UTC+12 itself. Since your ASP.Net code runs on the server it will always use the time on the server. The usual approach is, to save the timezone with the user data. I.e let the user select his/her timezone and calculate the proper time on the server. Or get the time on the client side and send it to the server. You get or set the CurrentCultureInfo or the CurrentUICulture on the running thread i.e. thread.CurrentCultureInfo. If you want to setthe Culture you create an object of type CulturInfo: CulturInfo ci = CultureInfo.CreateSpecificCulture("en-US") and then set the culture like this: Thread.CurrentThread.CurrentCulture = ci; Thread.CurrentThread.CurrentUICulture = ci; But as I said, this does not set the timezone, only the time format!!! Hope this helped Cheers Peter
Time:: 22:49
I'm surprised that this isn't possible. Do you know if it's possible in ASP.NET 2? Anyway you get your points for explaining it, thanks.
Time:: 23:01
Cheers for the points! Yes, it is a bit a pain, if you do global development. But think about it, how would you know what timezone the user is in? If you have users all around the world you will always have to transmit the timezone! The thing most people just need a while to completely understand is, that ASP.NET code runs on the server and only on the server! If you want to do client side scriptiong you have to fall back to VBScript or Java Script! I guess if you need a timestamp for a user activity, your best bet is to send the time to the server. Hey, but all is not lost. I just had a browse through one of my Java Script books. What you can do in JavaScript is: var today = new Date() offset = today.getTimezoneOffset() You save this in a hidden field and you can send the offset from UTC in minutes to the server. Relatively easy I would say. Cheers Peter
Time:: 23:12
Oh, yes, that's an option. The thing is that what I wanted was to save a timestamp on some of the information registered in the database and since the website has a fixed active timezone, but the server is in another, so it's not so much about displaying the time to the user as it is about recording it in the same timezone as all the rest of our activities. And I was surprised that there weren't any elegant solutions.
Time:: 23:49
Yes I understand. Then you will have to tell the server the timezone the user is in. I.e I am in New Zealand, that's UTC+12, Hans is in Germany, that's UTC+1. If the server is in a time zone i.e. UTC+5 if I save something to the database, I will have to tell the server "Use your time plus 7 hours" (UTC+12 - UTC+5 = 7), if Hans in Germany saves something, the server has to use its time minus 4 (UTC+1 - UTC+5 = -4) etc. There is no more elegant solution since the timezone is a user credential and you will have to tell the server this information. Hang on, I just found something else. There is a System.TimeZone class in .Net!!! It gives you the timezone based on the localization settings. But again, it will run on the server! Have a look at this webpage: http://www.csharphelp.com/archives/archi... And the TimeZone class is abstract so you can't create a timezone object and send it to the server. Not much help, is it? Cheers Peter
Time:: 23:57
yes, that's what I did, added 7 hours "manually" to the servers timezone. I'll have a look at the timezone class and see if that helps. Thanks a lot.
Date:: Jul 12, 2006
Time:: 00:10
Just one more thing! And then I'll shut up ;-) Look at the Qoumon time in each answer. You see that they obviously use the local server timezone. Where I live it is Wednesday, 10 am,12/07/2006. But my answers are marked with jul 11, 2006 23:57. And that's good. Just think about how confusing it would be if you write something on Tuesday, 23:00 and I'll reply with a time form Wednesday 10am and then you reply again with Tuesday etc. Confusing? You bet! So in some cases yo just want to use the timezone on the server. It is a generic setting. So think about the implication it wil lhave if yo change the time. Probably use two columns, one for server time and one for client time. I think it was a good discussion. At least it made me think about this a bit more. And that's what I like about Quomon Cheers Peter
Question Answered
This question has been closed, and points have been rewarded to the following experts:
You're welcome however to comment or give additional information or if you wish, you have the ability to write an Answer Summary for the Summary Area.
Answer this Question
New User
Email:
Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address
Registered User
Username:
Password:
Forgot Your Password?
Enter your email address below and we will resend your login information to you.
Login Information Sent
Time:: 23:02
Timezones can only be set from the client side using scrpting language. Timezone information will have to be send from the client to the ASP.NET server.
Click here to see the Answer Discussion that preceded this summary.
Login to rate this summary: Good | Bad
Questions
hover gallery.
How long does Google and MSN store emails that can...
Does the United States Government have a CIO posit...
How do you turn off the signature option in the ad...
audio quality- when playing music/video's, the sou...
Thanks for your reply. Where are you located? Whic...
You have 100 characters to use
Rank
Expert
Points
1.
738
2.
495
3.
450
4.
297
5.
215
6.
75
7.
50
8.
9.
10.
30
Register today to share your knowledge with the community and be recognized and rewarded for your contributions.
Register Here
"Psst, Quomon is a great site. Pass it on." Tell a Friend | Link To Us | Save to Delicious | Digg it
Language Options
English:
Español:
Sponsors
Questions and Answers Software Real Estate Postcards Marketing Fulfillment