[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

No it shouldn't.  It's behaving exactly as documented.  Read the
documentation for localtime.

} 
} 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 need to read the documentation for sprintf from the C library as
well.  The precision is a *minimum*, not an absolute.

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

-- 
Paul Schinder
schinder@pobox.com

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