Created
August 14, 2012 00:12
-
-
Save dex4er/3344991 to your computer and use it in GitHub Desktop.
TZ offset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use strict; | |
| use warnings; | |
| sub tz_offset | |
| { | |
| my $t = shift; | |
| my @l = localtime($t); | |
| my @g = gmtime($t); | |
| my $minutes = ($l[2] - $g[2] + ((($l[5]<<9)|$l[7]) <=> (($g[5]<<9)|$g[7])) * 24) * 60 + $l[1] - $g[1]; | |
| return $minutes unless wantarray; | |
| return (int($minutes / 60), $minutes % 60); | |
| } | |
| push @ARGV, time; | |
| foreach my $t (@ARGV) { | |
| printf "%s (%d): %+03d%02u\n", scalar localtime($t), $t, tz_offset($t); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| perl -MTime::Local -le '@t=localtime(time); $s=timegm(@t)-timelocal(@t); printf "%+03d%02u\n", int($s/60/60), $s%(60*60)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment