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

Re: [MacPerl] Strange time output



On Tue, Jan 11, 2000 at 07:18:02PM +0100, 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.
> 

The documentation can tell you why this happens.  Haven't you read it?

If you want a two-digit year:

$year %= 100;

Ronald

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org