in reply to User's time
The proper solution is to run localtime for a different timezone. At least on unices this can normally be done by setting the TZ environment variable. You can do that before even calling the program or at the very beginning of the program (probably even inside a BEGIN) if you want everything reported in Singapore time, or locally if you only want specific calls in Singapore time:
{ local $ENV{TZ} = "Singapore"; print scalar localtime; }
I could use "Singapore" as timezone name directly here since I have an entry named like that in my timezone database. That won't work on all operating systems though. Since Singapore doesn't do daylight saving, this one is probably more portable:
For other places you'd use their official timezone name that does have daylight saving, e.g. "CET" for central Europe.{ # Strangely enough I must use GMT-8 on my linux, even # though the official timezone name is GMT+8 (or UTC+8) local $ENV{TZ} = "GMT-8"; print scalar localtime; }
And in case you are on a system that doesn't react to TZ, you can (ab)use the fact that Singapore does no daylight saving by indeed working with an offset, but relative to gmtime:
Though that wouldn't of course generalize to places that do have daylight saving, or if Singapore ever introduces it.print scalar gmtime(8*3600+time);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: User's time
by kiat (Vicar) on Oct 16, 2004 at 09:37 UTC |