How to get times in different timezones? 
Author Message
 How to get times in different timezones?

Hi, I'm a Perl newbie trying to figure out how to calculate time of day
in various time zones taking into account daylight savings time.  For
example, getting GMT was easy, but how do I then figure out the correct
time in Hong Kong if my machine's not in Hong Kong?

Thanks,
Peter



Sun, 08 Oct 2000 03:00:00 GMT  
 How to get times in different timezones?


Quote:
> Hi, I'm a Perl newbie trying to figure out how to calculate time of day
> in various time zones taking into account daylight savings time.  For
> example, getting GMT was easy, but how do I then figure out the correct
> time in Hong Kong if my machine's not in Hong Kong?

> Thanks,
> Peter

You dont have to do any working out at all... Thats what localtime() is for.
Localtime (at least on my UNIX system) looks at the TZ (TimeZone) environment variable
to calculate the localtime from UTC.
You can try setting your TZ to something like NZST-12NZDT (New Zealand) and check that it works.

James

PS: Did you check dejanews first... cos the answer is there too.....(08/04/98)



Mon, 09 Oct 2000 03:00:00 GMT  
 How to get times in different timezones?

Quote:


>> Hi, I'm a Perl newbie trying to figure out how to calculate time of day
>> in various time zones taking into account daylight savings time.  For
>> example, getting GMT was easy, but how do I then figure out the correct
>> time in Hong Kong if my machine's not in Hong Kong?

>You dont have to do any working out at all... Thats what localtime() is for.
>Localtime (at least on my UNIX system) looks at the TZ (TimeZone)
>environment variable to calculate the localtime from UTC.
>You can try setting your TZ to something like NZST-12NZDT (New Zealand)
>and check that it works.

Note that on most systems, localtime remembers the TZ value on its first
call, and doesn't look at the environment variable again (an optimisation).
So you can't refer to more than one time zone in a single Perl run
(without doing some special poking in the innards).

You need to set the TZ environment variable _before_ calling perl.

Mike Guy



Wed, 11 Oct 2000 03:00:00 GMT  
 How to get times in different timezones?

Quote:

>Note that on most systems, localtime remembers the TZ value on its first
>call, and doesn't look at the environment variable again (an optimisation).

That used to be true long ago, but POSIX.1 requires that localtime not
cache TZ, and these days most implementations obey POSIX.1 in that respect.


Fri, 13 Oct 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Perl script to serve up different HTML pages at different times of day

2. Getting UTC of a particular calendar time in some time zone

3. unpack(), CRCs, /bin/sum - getting different values.

4. Getting a File From A Different Server...

5. Getting value of a variable in different file

6. Getting Different Behavior from Perl Script and Unix Command

7. getting perl system calls to run in different shells

8. formmail: different form data gets mixed up

9. changing time to different format

10. Timezones

11. Convert GMT to North American timezones

12. Timezones

 

 
Powered by phpBB® Forum Software