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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating international time

Status
Not open for further replies.

AndyGroom

Programmer
May 23, 2001
972
0
0
GB
Can anyone help me out with some code for working out what the time is in another country, taking daylight saving time into account where necessary?

I've tried searching for a solution but all I can find are finished products, not source code.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
OK, so here's where I'm at, having used various bits of code from the above examples.

I can now get a list of bias values pertaining to the time zone for which I want to find out the local time. (For this example I'll use New Zealand since it was in the original example). For New Zealand it's -780.

I pass -780 in the .Bias property of a TZI structure along with the system time as returned by GetSystemTime, into the SystemTimeToTzSpecificLocalTime function.

Assuming that I try this at 8pm on Wednesday, it returns 8am Thursday as the time in New Zealand, which is one hour fast (it should return 7am).

So, what further adjustment should I be doing in order to get the right time?

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
You need to copy Bias, StandardBias, DaylightBias, StandardDate and DaylightDate from the REGTIMEZONEINFORMATION that you retrieve from the registry into the TIME_ZONE_INFORMATION that you are going to pass to the SystemTimeToTzSpecificLocalTime
 
Thanks, I now have a working solution.

Do you know whether the names of the time zones listed in the Registry (eg "Mexico Standard Time") are always in English regardless of the localisation of Windows? So, if someone is using my program in Arabic Windows can I still look up "Mexico Standard Time" in the registry and read the values or will it not find it?

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
As far as I know the keynames stay the same no matter what locale you are in. The Display, Dlt and Std strings under the key may change though - but this is probably unimportant to you
 
The only catch is that sometimes a state or country will vary it's local time to an adjoining one even though they are on the same longitude.
Windows doesn't provide for that, only going for the area with the largest population in each zone.

With the recent changeover from daylight saving time some states in Australia delayed the changeover by a week but others didn't to save power & greenhouse gases. Twilight lasts a lot longer in southern areas closer to the poles.

I suspect this will be the rule rather than the exception in the future.
 
>Windows doesn't provide for that

It has a pretty good stab at it, to be honest. Technically there are only 25 (integer) world time zones. But Windows breaks that into 84, which gives a reasonable chance of getting a time zone that works for your area.

Also, the list is not immutable. It is updated reasonably regularly (at least annually), and I see no reason if new zones genuinely come into existence not to have them added to the list.

>some states in Australia delayed the changeover by a week

Well, once you start doing this you are no longer running to standard time, and one you are no longer running to stanbdard time then you can't be in a time zone, so you deserve to have computers ignore you and find you don't arrive at any of your meetings on time ... ;-)
 
<you deserve to have computers ignore you

I though the original questioner wanted to know reliably what the time was in zones other than himself.

His 'meetings' might very well be "on line".

I was pointing that you really can't using only Windows.
 
>what the time was in zones other than himself

And he can do that. If areas choose to not be in a recognized time zone then in theory all bets are off.

But of course what you are failing to recognize is that that is only the case if you stick with the settings in the registry. If for some reason a country or state or, heck, a village or your home decided to do something completely different you can ALWAYS load the TZI structure with the correct info about the aberration, and the time for the aberration will then be calculated correctly using exactly the methods described here.

In other words the TZI info in the registry is NOT a proscriptive list. It is just handy for the known, recognised time zones.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top