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
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 !
I will need to fix this until midnight, duh…
midnight bug and timezone with minutes fixed
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. )
if you live in Zurich, at 1am in Summer you should get +2 and not -22
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.
What’s wrong with just
date +%z’
?
This is OS specific.