> -----Original Message-----
> From: Toby Stuart [mailto:[EMAIL PROTECTED]]
> Sent: Monday, December 16, 2002 4:17 PM
> To: '[EMAIL PROTECTED]'
> Subject: RE: localtime question - zero padding - mnth discrepancy
> 
> 
> 
> 
> > -----Original Message-----
> > From: Harry Putnam [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, December 16, 2002 3:15 PM
> > To: [EMAIL PROTECTED]
> > Subject: localtime question - zero padding - mnth discrepancy
> > 
> > 
> > 
> > I really have two questions here:
> > 
> > 1) How can I get padded numbers in the single digit range in this
> >    script?
> 
> 
> Check the length of second, minute and hour.
> If the length == 1 then add a leading zero eg. $sec = "0" . $sec
> Maybe there is some other "magical" way of doing this, if 
> there is i'm not
> aware of it :)
> 

Actually, checking the length of hour is not necessary as it is 24 hour
time.


> 
> 
> > 2) Hoping tbis isn't some glaring mistake and I'm too blind 
> to see it.
> >    Notice how the month is off by 1
> > 
> 
> 
> perldoc -f localtime
> Basically it says that:   0 = January and 11 = December
> So just increment $month ie. $month++
> 
> 
> 
> > cat test.pl
> > 
> >   #!/usr/local/bin/perl -w
> >   $now = time;
> >   ## 1 day = 86400
> >    
> >   $date_spec = ($now - 86400);
> >   # local time adjusted
> >   @lta = localtime($date_spec); 
> >   
> >   # 0=second
> >   # 1=minute
> >   # 2=hour
> >   # 3=day of mnth
> >   # 5=year
> >   # 4=mnth
> >   # 6=day of week
> >   
> >   print " $lta[4]/$lta[3]/" . ($lta[5] += 1900) . " 
> > $lta[2]:$lta[1]:$lta[0]\n";
> >   print localtime() . "\n";
> > 
> > OUTPUT:
> > 
> >  11/14/2002 20:9:4
> > Sun Dec 15 20:09:04 2002
> > 
> > Notice how the bare print on `localtime()' gives the 
> desired padding.
> > Notice how the eleventh mnth is reported in the adjusted time.
> 
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to