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

Re: [MacPerl] 1900-2000 problem.



Some time around 12/18/97 1:30 PM CDT, Juergen Christoffel wrote 
something about

>At 19:55 +0100 18.12.97, Anders Gardebring wrote:
>>Just a small question.
>>Is it possible to ask MacPerl to give 4 figures rather than two when Im 
asking
>>for the year?
>>Now Im doing like this:
>>
>> @date = localtime;
>>        $date[5] +=1900; # Add 1900 to the year....
>>
>>This is of course not so good when we pass year 2000....
>>Any help greatly appreciated :)
>
>When we pass 1999 Perl will return a year with 3 digits, so you should
>simply add 1900 to the year and always get the correct year.
>
>But you can use localtime in a scalar context instead of an array context
>and then you get a date line with a four digit year.
>
>$s = localtime;
>print $s, "\n";
>
>WIll print something like "Thu Dec 18 20:29:30 1997" which you can split
>and pop to get the four digit year.
>
>Strange but totally Perl ;-)

     I was just starting to write my response when this came in, so 
here's an addendum to the already correct response from Juergen:

     The Date::Format module, available from CPAN in 
modules/by-module/Date/TimeDate-1.07, is an excellent tool for quickly 
getting dates output in whatever form you want... you just pass it a 
template similar to a printf template and voila, your custom date string 
is returned, with no fuss and muss trying to parse out localtime for 
yourself.

Enjoy,

Dave Beverly (hUmAnErrOr)
webmaster@thecitizennews.com -- http://www.thecitizennews.com/
webmaster@henrynews.com -- http://www.henrynews.com/
Mac Manipulator -- "I don't do windows!"


---
smash the control images...
smash the control machines...

just say no to Bill
(Gates or Clinton, take yer pick)


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