Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: How to get TZ difference?

by Anonymous Monk
on Sep 08, 2014 at 09:42 UTC ( #1099854=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1099854]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2022-09-24 19:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (115 votes). Check out past polls.

    Notices?