[sf-perl] Timezone question

Joseph Brenner doom at kzsu.stanford.edu
Mon Aug 20 17:56:13 PDT 2012

Earl Ruby <earl at ruby.org> wrote:
> Does anyone know of a CPAN function that, when passed the name of a
> timezone from zoneinfo (e.g. "America/Los_Angeles") and whether or not
> daylight savings time is in effect will return the UTC offset in
> seconds?
> I've looked through CPAN and several modules look like they do this
> but don't. Either they don't work with the zones from zoneinfo or they
> won't give the offsets for standard and daylight time (only "current"
> time).

Have you looked at DateTime::TimeZone?


You can use it like this to get the offset:

  use DateTime;
  use DateTime::TimeZone;

  my $tz = DateTime::TimeZone->new( name => 'America/Chicago' );

  my $dt = DateTime->now();
  my $offset = $tz->offset_for_datetime($dt);

And I would guess you could use "is_dst_for_datetime" to
determine if you're in daylight savings time.

More information about the SanFrancisco-pm mailing list