Time offset in Unix

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

perl -e '
$t=time;
@l=localtime($t);
@g=gmtime($t);
$d=$l[2]-$g[2]+($l[1]-$g[1])/60;
$gd=$g[3]+$g[4]*31+$g[5]*365;
$ld=$l[3]+$l[4]*31+$l[5]*365;
if($gd<$ld){$d+=24}; if($gd>$ld){$d-=24}
print ($d."\n")'
2

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

7 thoughts on “Time offset in Unix

  1. Laurent Schneider Post author

    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. Karoly

    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. Karoly

    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.

Comments are closed.