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

Re: [MacPerl] Strange time output



On Wed, Jan 12, 2000 at 01:32:40AM +0100, Martin D. wrote:
> At 14.08 -0500 0-01-11, Ronald J Kimball wrote:
> >The documentation can tell you why this happens.  Haven't you read it?
> >
> >If you want a two-digit year:
> >
> >$year %= 100;
> 
> Yes, I'm guilty of not having read the perlfunc.pod on localtime before
> posting *ashamed*. Had I done that I would have noticed that time begins
> 1900... Regardless of that, I wouldn't have figured why I got three digits
> when using sprintf(%02d), not that that's an excuse for not reading up on
> localtime before posting but I wish it could be;).
> 
> I ended up using:
> $timestamp = sprintf("%02d-%02d-%02d\n", $year-100, $month+1, $day);

That's a Y3K bug.  And it will give negative numbers if you use it for past
dates.  Instead, use % 100, as I suggested.

$timestamp = sprintf("%02d-%02d-%02d\n", $year % 100, $month+1, $day);

Ronald

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