For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > October 2006 > Re: getting a 2 digit readout no matter what









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: getting a 2 digit readout no matter what
Bryan R Harris

2006-10-04, 9:57 pm



> Hello all. Trying to get a 2 digit readout from $hour pulled from
> localtime. How can I do this?
>
> This is running on a sun box, so I also tried pulling from:
> $string = system "date"; but if one digit, it will not put a "0" in front.
>
> But this doesn't only seems to assign "0". And it prints output
> correctly, but not assigning it to my string.
>
> Ugh, I hope I explained this right. I'm a beginner in the rough. ;->



Here's how I do it:

($sec,$min,$hour,$mday,$mon,$year) = localtime;
printf "%02d%02d%02d-%02d%02d%02d)\n", $year % 100, $mon+1, $mday, $hour,
$min, $sec;

- B

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com