Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Localtime() or gmtime()

by Flexx (Pilgrim)
on Oct 15, 2002 at 00:52 UTC ( #205257=note: print w/replies, xml ) Need Help??


in reply to Localtime() or gmtime()

Hi,

Altering your $ENV{TZ}, for a very quick hack could do. A local $ENV{TZ} = 'EET' # EET? is a bit better.

But beware (know what you do)! This is potentially dangerous, if you use qx// or [system]() calls, require other perl scripts/use modules, do IPC (interact with other running processes), have changing configuration (see below), etc.

In a production script/environment you'll want to use a Date/Time manipulation module, like the excellent Date::Manip or Date::Calc. These will do what you need (and more), safely with regard to daylight saving times and/or configuration changes. Imagine what happens if your servers' sysop one day decides he'd switch his servers to use UTC as their RTC's timezone. These modules will return the correct date, simply adding the n hours offset will fail in such a case...

Times are just data. Operate on it. If you want to know what time it is in Zimbabwe, you'd calculate the difference to your local time -- you wouldn't reset your wristwatch (i. e. change your configuration) to see what the time would be (I hope ;)...

Hope this helps a bit,

so long,
Flexx

Replies are listed 'Best First'.
Re: Localtime() or gmtime()
by Abigail-II (Bishop) on Oct 15, 2002 at 08:20 UTC
    Imagine what happens if your servers' sysop one day decides he'd switch his servers to use UTC as their RTC'S timezone. These modules will return the correct date, simply adding the n hours offset will fail in such a case...

    Times are just data. Operate on it. If you want to know what time it is in Zimbabwe, you'd calculate the difference to your local time

    So, what is it? Can you, or can't you calculate the difference? First you say you can't, then you say you can.

    Also, how would Date::Manip or Date::Calc continue to return "the correct date" when the server switches timezones (wrongly apparently, otherwise localtime() would return the correct time).

    Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://205257]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (1)
As of 2021-02-25 02:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?