in reply to User's time

Doing a fixed offset and then using localtime is a bad idea since it doesn't account for differences in daylight saving. Even if both source and target area do daylight saving, they likely will not have them over the same periods of 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:

{ # 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; }
For other places you'd use their official timezone name that does have daylight saving, e.g. "CET" for central Europe.

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:

print scalar gmtime(8*3600+time);
Though that wouldn't of course generalize to places that do have daylight saving, or if Singapore ever introduces it.

Replies are listed 'Best First'.
Re^2: User's time
by kiat (Vicar) on Oct 16, 2004 at 09:37 UTC
    Thanks, thospel!

    I didn't know there's so much involved. I'll try with your more portable solution below:

    local $ENV{TZ} = "GMT-8";