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

Re: [MacPerl] New to Perl on Mac



On Mon, 26 Jan 1998 10:10:19 -0600 (CST) mark@cheers.jsc.nasa.gov (Mark
Manning/Muniz Eng.) wrote:

>You should always use the localtime function - not a system
>call.  Which is what the backtick does in this case.  Here
>is some code:
>
>    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
>localtime(time);
>    $mon += 1;
>    $curDate = sprintf( "%.2d/%.2d/%.2d %.2d:%.2d:%.2d", $mon, $mday,
>$year, $hour, $min, $sec );
>
>Notice that everything always counts from ZERO.  Whether it
>be the seconds, minutes, hours, days, years, or whatever.
>That is why $MON has one added to it.

Lots of good information in that note from Mark.  One note, though, on
the above passage: $mday and $yday aren't zero-based, to my knowledge.
Also, $year is the year - 1900.  (So as to avoid any resurgence of the
year-2000 discussion)  While that means it presents two digits now, for
years after 1999, it will be three digits.  (And, presumably, for years
after 2899, it will be four digits, but if you're planning code that far
in advance, I'm impressed.)

For the scoop on localtime, you can refer to Camel (2d ed) p. 185 or
Camel (1st ed) p. 159.

HTH,

-Aaron

------------------------------------------------
Aaron Munter, Technology Development Coordinator
Salem-Keizer Public Schools, Salem, Oregon, USA
http://www.salkeiz.k12.or.us/


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