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

Re: [MacPerl] Strange time output



At 19.18 +0100 2000.01.11, Martin D. wrote:
>#! perl -w
>
>($day, $month, $year) = (localtime) [3,4,5];
>$timestamp = sprintf("%02d-%02d-%02d\n", $year, $month+1, $day);
>
>print "$timestamp";
>
>this produces:
>100-01-11
>
>Shouldn't it produce:
>00-01-11
>
>Can anyone tell me why this happens? $year is formatted to be two digits I
>can't see how I suddenly get three... and 100 at that.

You can't do that with %d.  Try doing $year % 100 or something.

-- 
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 macperl-request@macperl.org