Skip to content

Instantly share code, notes, and snippets.

@dex4er
Created August 14, 2012 00:12
Show Gist options
  • Select an option

  • Save dex4er/3344991 to your computer and use it in GitHub Desktop.

Select an option

Save dex4er/3344991 to your computer and use it in GitHub Desktop.
TZ offset
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);
}
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