Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need some help on Time zone related problem. 1

Status
Not open for further replies.

vikaskalra

Technical User
Aug 12, 2002
41
GB
Hi All!

Need some help on Time zone related problem.

I have a .NET (ASP.NET) based app with MS-SQL Server 2000.My site is hosted at a California based server, basically people from two locations will be logging on this site, ones from UK (London) and from anywhere in US.

The problem is I need to distinguish between the two and maintain a uniform time, if a person stationed in US, posts an Invoice and a person in UK wants to review it in UK, it should convert the time to UK specific date and time and vice-versa.

Second, if a person logs in from London, the currency shown to him will be Pounds, and if from US, then $, both multiplied by the respective conversion factors.

I wanted guidance from you guys, if by some way, say from the IP of the person accessing the site, I could track that this person is logging in from UK or US and do the conversions on the fly ? or is there any other solution for this problem ? I don't want to maintain multiple date time columns in the Database.

Thanks,
Vikas

 
Regarding the time issue:

Store all date/times as GMT/UTC. When a user asks for it to be displayed, use their CultureInfo information (see System.Globalization namespace) to format the date for their timezone.

Each user would have a culture name, which is defined by the .NET docs as:
The culture name in the format &quot;<languagecode2>-<country/regioncode2>&quot;, where <languagecode2> is a lowercase two-letter code derived from ISO 639-1 and <country/regioncode2> is an uppercase two-letter code derived from ISO 3166.

So your London user would have &quot;en-UK&quot; and your US user would have &quot;en-US&quot;. This ensures that your UK users see dates as day-month-year, and the US users see dates as month-day-year.

Converting the stored date/time to the local time is a function of the TimeZone class (in System namespace). Use the ToLocalTime() method to convert your stored UTC time to the user's local time. It gets the local timezone from the user's computer settings.

Chip H.
 
Hi Chiph & Chmohan!

Thanks for your posts! It worked fine !

Regards,
Vikas
 
Can you tell me how to get the time of all our offices using
timeZone?

I can't create a timeZone other than the currentTimezone so if my server is in amsterdam and I want to display the time in Tokyo I have a problem.

I can calculate the UTC offset with the timeZone of Amsterdam but not with the timeZone of Tokyo since the server is in amstedam and has its time set to Amsterdam.

Cannot just add or remove a couple of hours from Amsterdam time to get the Tokyo time because Amsterdam uses daylight saving time and Tokyo doesn't.

I have to figure out the local time of 20 offices arround the word, thought I do it by setting a timezone on the TimeZone object but that is not possible.

Is there an object available that can tell me the time in other parts of the world using a .net object. There is one available in java but I can't use it:



Greetings, Harm Meijer
 
If you're writing a web app, you'll need to use some javascript or other client-side code to determine what the timezone offset is. Have your server-side code send all date/time info in UTC, and when it gets to the client-side code, have it subtract the correct number of hours. Do this in reverse when sending data to the server to convert back to UTC.

If you're writing a client-server app, the situation is the same, only it won't be javascript doing the work -- it'll be whatever language you write the client app in.

Yes, it's a pain. But only the client's PC knows what timezone it's in.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Thank you for your response Chip, if there is no object in .net that can do this I will create an applet that will do it.

> have it subtract the correct number of hours

That means I have to program the dst myselve for all 20 or so offices.

Is there no object where you can set the timezone? Msjvm (java 1.1 5 years ago!!!) can create a timezone object setting the timezone (or list through all available) and display the current time for all those zones. It's hard to beleave they didn't do it in .net but I can't find any way to set the timezone other than currentTimezone.

I would probably need all available zones since the next question will be: "I have to call a client in ... but we don't have an office there so your page doesn't display the time of ... Can you ..."

I know there are web sites available where you can get the local time of all major cities but that is not good enough for people here, they want it on the intranet.



Greetings, Harm Meijer
 
That means I have to program the dst myselve for all 20 or so offices.

Each PC will report it's timezone. If the PC is set wrong, then the values will be shown to the user incorrectly. But the application will still function because those values are changed to UTC before being sent to the server by client-side code.

I know there are web sites available where you can get the local time of all major cities but that is not good enough for people here, they want it on the intranet.

Create a database table that stores your business locations, and put each location's timezone offset in there:
New York: -5
London: 0
Frankfurt: 1

The Timezone class has a GetDaylightChanges method, but since you can't construct a TimeZone object for an arbitrary timezone (as you've discovered), it isn't of any use to you. If you look, a TimeZone object can only be created for the current timezone, meaning the timezone that the computer is in. Which is why I was saying that the client has to provide it. Or... look it up in a table.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
I used java TimeZone object to generate javascript. Because not all users hava SUN jre installed.

Works OK for the next 10 years, the database you talk about is a good idea but that means inserting all major cities, theire UTC offset and DST period. The TimeZone in SUN jre has 400+ major cities in there and the needed info to get UTC offset (with DST).




Greetings, Harm Meijer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top