Perl question

Kevin Buettner plug-devel@lists.PLUG.phoenix.az.us
Mon May 21 11:42:44 2001


On May 22,  7:47pm, Carl Parrish wrote:

> Okay I should give more info. I'm going to need to deploy this 
> application on several servers all of which are going to be in seperate 
> time zones. However I want the time displayed to be the same. I'm 
> assuming that all of the admins are going to want it to be in EST. So 
> what i'd like to do is code them all to get the time from some central 
> server running on EST without messing with the local time.

Are you concerned about keeping the machines synchronized?  Or do you
just want to display a uniform TZ regardless of where the machine is
located.

If you're worried about synchronization, just use an NTP daemon or the
like to keep the machines synchronized.

If you want to control the time zone that localtime uses, just set the
TZ environment variable.  E.g, try this:

    perl -e '$ENV{TZ}="EST"; print scalar(localtime(time)), "\n"'

or

    perl -e '$ENV{TZ}="US/Eastern"; print scalar(localtime(time)), "\n"'

(Note that these are actually different time zones.)

And then try this:

    perl -e '$ENV{TZ}="MST"; print scalar(localtime(time)), "\n"'

Finally, if you really, really do want to fetch the date from a single
server, you could try something like

    $date = `rdate $servername`

where $servername is set appropriately.  I really don't think it's worth
doing this though.  Keeping your machines synchronized with NTP should
yield much better results.

Kevin