http://www.perlmonks.org?node_id=1099854


in reply to Re: Re: How to get TZ difference?
in thread How to get TZ difference?

you forgot to compare the months in case when we have last day of the month, around midnight it will return inccorect results

Replies are listed 'Best First'.
Re^4: How to get TZ difference?
by Anonymous Monk on Sep 14, 2016 at 18:37 UTC
    perl -e 'print ( ( (localtime)[2] - (gmtime)[2] + 12 ) % 24 - 12 )'

    ...works across midnight, end of month, etc without all those pesky conditionals. Works because perl has a useful definition of modulo operator (%) for negative operands, but beware this can be compromised in certain situations. See perlop#Multiplicative-Operators.