7is7.com > Software > Perl Tips
Linux Penguin

Perl Tips

This page contains a selection of tips for Perl (on Linux and UNIX) that I have collected. It's more of a memo to myself and not intended as a guide or anything. So just see it as notes that I share with whoever is interested.

Get the timezone

Perl sub to return the timezone in ±HH:MM format.

use Time::Local;

sub retTimezone {
    my $offset = (&timegm(localtime) - time) / 60;
    return sprintf("%+03d:%02d", int($offset / 60), $offset % 60);
}

The other sub doing the rounds on the web, does not work properly for timezones that are not whole or half hour offsets, like Nepalese time, which is at +05:45.

 


Linux user 425492

Get Firefox! Download LibreOffice Use Fedora