Search code examples
perltimezonesolarisepoch

How can I change the timezone of a datetime value in Perl?


Using this function:

perl -e 'use Time::Local; print timelocal("00","00","00","01","01","2000"),"\n";'

It will return an epochtime - but only in GMT - if i want the result in GMT+1 (which is the systems localtime(TZ)), what do i need to change?

Thanks in advance,

Anders


Solution

  • There is only one standard definition for epochtime, based on UTC, and not different epochtimes for different timezones.

    If you want to find the offset between gmtime and localtime, use

    use Time::Local;
    @t = localtime(time);
    $gmt_offset_in_seconds = timegm(@t) - timelocal(@t);