Getting TZ in HH:MM, portably
Leif Sawyer
lsawyer at gci.com
Thu Jul 29 13:27:42 CDT 1999
Of course, this works.. (and for some reason i didn't
think of it before)
use Time::Local;
sub get_tz_offset {
my $offset = sprintf "%.1f", (timegm(localtime) - time) / 3600;
my $minutes = sprintf "%02d", ( $offset - int($offset) ) * 60;
return(sprintf("%+03d%s", int($offset), $minutes) );
}
Leave it to a perl monger to supply his own fix... :-)
> -----Original Message-----
> From: Michael Fowler [mailto:wolfm at pobox.alaska.net]
> Sent: Wednesday, July 28, 1999 11:56 AM
> To: Leif Sawyer
> Cc: Anchorage Perl Mongers
> Subject: Re: Alaska Perl Mongers Site reworked. . .
>
>
> The strftime function has a (apparently undocumented)
> specifier, %z, on my
> system. It returns an rfc822 numeric timezone, an offset from GMT.
>
> I don't know how portable this is, considering it's
> undocumented. You may
> want to use the Time::Timezone module, which provides the
> tz_local_offset and
> tz_offset functions. Alternatively, you can use the
> Date::Format module's
> strftime function, which documents the %z, and has quite a few other
> specifiers besides. Both modules can be found on CPAN.
>
> With any of the solutions you're going to get -0800, instead
> of just -8.
> This is to allow for half-hour timezone offsets, as well as
> offsets above 9,
> while still being easy to parse.
>
>
> Michael
>
>
> On Wed, Jul 28, 1999 at 11:15:54AM -0800, Leif Sawyer wrote:
> > I've just stumbled across an interesting problem
> > that I can't dredge up the answer to.
> >
> > I need a function to return the offset for the current timezone.
> >
> > I can do the following:
> >
> > perl -e 'use POSIX; print POSIX::strftime("%T %D (%Z)\n")'
> >
> > which outputs
> >
> > 11:10:00 07/28/99 (AKDT)
> >
> > What i need is to have:
> >
> > 11:10:00 07/28/99 -8 (AKDT)
> >
> > Any thoughts?
> > =================================================
> > Mailing list info: If at any time you wish to (un|re)subscribe to
> > the list send the request to majordomo at hfb.pm.org. All requests
> > should be in the body, and look like such
> > subscribe anchorage-pm-list
> > unsubscribe anchorage-pm-list
>
=================================================
Mailing list info: If at any time you wish to (un|re)subscribe to
the list send the request to majordomo at hfb.pm.org. All requests
should be in the body, and look like such
subscribe anchorage-pm-list
unsubscribe anchorage-pm-list
More information about the Anchorage-pm
mailing list