Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

i need to have a subroutine to which i can supply a gmt offset (ex: -6 for Central Standard Time), and have it return to me an array like what one would get from local().

is there anything like this already existing, or will i have to write one myself? for example:

print 'enter gmt time offset: '; $offset = <>; # sample input would be '-6' or '3', etc ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localToOffset($offset +);

Replies are listed 'Best First'.
Re: getting time local to a user supplied offset...
by bobn (Chaplain) on Jul 21, 2003 at 00:33 UTC

    gmtime provides UTC. Feed it time() +/- the right number of seconds and you're done.

    # Untested print 'enter gmt time offset: '; $offset = <>; # sample input would be '-6' or '3', etc ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime(time() +$offse +t * 3600); $offsettime = ''. gmtime(time() +$offset * 3600);
    --Bob Niederman, http://bob-n.com
      it sort of works, but its off by 6 hours...

        You caught me while I discovered that I wanted gmtime(), rather than localtime().

        --Bob Niederman, http://bob-n.com