Thursday, January 22, 2015

How to Find UTC Time Offset from your Local Time?

This is the sample script to find the offset in seconds of your local time from GMT.
#!/usr/bin/perl
use strict;

use POSIX;

my @local = localtime();
my @utc   = gmtime();

my $timezone_offset = mktime(@local) - mktime(@utc);

print "Offset in second(s) from GMT = $timezone_offset\n";
print "Offset in hour(s) from GMT = " . ($timezone_offset / 3600) . "\n";

Output:
Offset in second(s) from GMT = 28800
Offset in hour(s) from GMT = 8

No comments:

Post a Comment