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

Re: [MacPerl] Perl date comparisons



At 17.58 -0500 1998.11.16, Aiken, Greg wrote:
>I know that 'time()' returns the number of elapsed seconds between
>01-01-1970 and the instant the function is called.

No you don't.  :)  It actually returns the seconds since the epoch, which
for Unix is Jan 1, 1970 00:00:00 GMT, and for Mac OS is Jan 04, 1904
00:00:00 local timezone.

See perlport.pod, on CPAN and in perl5.005.

>Yes, I realize I could 'hack' at this function myself.  But there are
>probably enough special rules (ie; leap years - unless evenly divided by
>100, daylight savings, etc...) that I would not be knowledgeable about -
>that my seconds surely would not match the seconds returned by 'time()'.
> Any help would be appreciated.

There are plenty of Date:: modules that can help you deal with this.  I am
not sure exactly what you want, but Time::Local (which comes with perl)
might do what you want.

#!perl -w
use Time::Local;
$t = (time - timelocal(0, 1, 18, 15, 10, 98))       # Nov. 15, 18:01 GMT
  + (timelocal(gmtime()) - timelocal(localtime())); #adjust for timezone
$d = $t/86400;
$h = $t%86400;
$m = $h%3600;
$s = $m%60;

printf "It has been %d days, %.2d hours, %.2d minutes, " .
  "and %.2d seconds since the Patriots - Bills game began.\n",
  $d, $h/3600, $m/60, $s;

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

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