http://qs321.pair.com?node_id=205257


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