[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Q on Mac Time Zones



Chris Nandor wrote:
> 
> At 01.02 -0500 1999.01.08, Walter Torres wrote:
> >Any one have any idea on how to get the Time Zone setting out of the Mac?
> 
> Untested in other places, but should work anywhere, I think:
> 
>   #!perl
>   use Time::Local;
>   $diff = (timelocal(localtime) - timelocal(gmtime)) / 36;
>   $diff =~ s/^-?(\d{3})$/-0$1/;  # add leading zero if only three digits
>   print $diff;
> 
> On my Mac, $diff is -0500 (which is correct for the East Coast this time of
> year).
> 

Try this instead:

  #!perl
  use Time::Local;
  $diff = (timelocal(localtime) - timelocal(gmtime)) / 36;
  $diff = sprintf "%+0.4d", $diff;  # add sign, leading zero(es)
  print $diff;


Should work anywhere, even those funny timezones that don't have a negative
offset from GMT.  :-)

Ronald

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch