Time offset in Unix

What is the time offset of the current date in Unix?

perl -e '
if($gd<$ld){$d+=24}; if($gd>$ld){$d-=24}
print ($d."\n")'

Am I in summer (DST)?
perl -e 'if((localtime)[8]){print"yes"}else{print "no"}'

By Laurent Schneider

Oracle Certified Master


  1. actually this was a tentative to improve
    echo $(($(date +%H)-$(date -u +%H)))
    because if “date” is executed twice, once at 17:59:59.999999999999 and once at 18:00:00.00000000001, you could hit a bug !

  2. In my rss reader ist the first version, what you wrote as oneliner in perl.
    What is the problem with them?

    Ps: This is what i say every time to the newbies. Perl, awk, all the unix tools are powerful, that you can’t believe it. Try it, then you understand it. ( I don’t say it you, of course. )

  3. Sure, you have right. I don’t live in Switzerland, and I don’t tested it at midnight.
    Maybe the best solution: You make a cronjob, which is run at 2:15. Then you have always the right offset. 😉

    Ps: I’m currently in Germany. I was only once in Zurich. It is nice. Some friends of me living there.

Leave a comment

Your email address will not be published.