Showing posts with label timezone. Show all posts
Showing posts with label timezone. Show all posts

Wednesday, February 4, 2009

Time zone calculator

To work out local GMT time use something like:


use POSIX qw(strftime);
strftime "%a %b %e %H:%M:%S %Y", gmtime;

Then either deduct or add in seconds, to work out time in a different time zone. Something like this:

# or for GMT formatted appropriately for your locale:
my $london = strftime "%a %b %e %H:%M:%S %Y", gmtime;
print "London $london\n";

# 8h * 60 min = 240 * 60 sec = 28800
my $seattle = strftime "%a %b %e %H:%M:%S %Y", gmtime(time - 28800);
print "Seattle $seattle 8 hours behind\n";

Nothing crazy, but useful.