Time Zones

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Time Zones

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:59 pm

by Iain Kerr >> Mon, 16 Feb 2009 5:42:48 GMT

Hi
Does anyone know how to get the time in a specifc place on the planet.

I am writing an application where the user is located at Place A and another non user provides information in their local timezone B over the phone. I need to record what the real time is in the other location. Too hard for the other user to work out what the time is in Place A. They also may be reporting things that happened at time xxx a few days ago in Place B

I also need to be able to work out the time in Place A when it was time xyz in Place B at some point in the past

Regards
Iain

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Time Zones

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:59 pm

by Torrie Moore >> Mon, 16 Feb 2009 19:47:45 GMT

Hi

Try the following methods on TimeStamp

localToUTCTimeUsingBias
utcToLocalTimeUsingBias
localToUTCTime
utcToLocalTime

and on Application

currentUTCBias

These should allow you to convert the times from the other location to the UTC and then you can convert that back to the local time. Might be worth storing all times in UTC so that there's no confusion. You may need to store the locations with their bias to make things easier.

Torrie

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Time Zones

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:59 pm

by Iain Kerr >> Mon, 16 Feb 2009 22:29:50 GMT

Thanks Torrie
I thought there may be a more sophisticated solution.
I take it we need to then create some classes in our application that hold the Bias including a history for each of the TimeZones in which we are interested. We can then use this together with the methods you have highlighted to get the correct answer. Updating of the TimeZone class with the changes for Daylight Saving would be done by a user through a suitable GUI

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Time Zones

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:59 pm

by Torrie Moore >> Thu, 19 Feb 2009 21:53:07 GMT

Hi Iain

If you're running on Windows, you may be able to use the Registry and Time API's to determine the timezones and biases. Take a look at http://msdn.microsoft.com/en-us/library ... S.85).aspx for information about how windows stores the time zones in registry (in the remarks section at the bottom) and also at http://msdn.microsoft.com/en-us/library ... S.85).aspx for the time functions available. The GetTimeZoneInformationForYear function looks to allow you to retrieve the information for any time zone (and date).

Regards

Torrie

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Time Zones

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:59 pm

by BeeJay >> Fri, 20 Feb 2009 0:11:08 GMT

The GetTimeZoneInformationForYear function does have some fairly restrictive OS requirements though:

Minimum supported client Windows Vista with SP1
Minimum supported server Windows Server 2008

Cheers,
BeeJay.


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 10 guests