I’ve looked over the Perldocs at localtime but I’m still pretty confused about how to get the current time in the hh:nn:ss format, such as 20:17:54, or 09:45:00.
Could someone point me in the right direction?
Technorati Tags: current time, hh, localtime, nn, right direction, ss format
This entry was posted
on Tuesday, July 20th, 2010 at 7:11 am and is filed under perl.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
July 20th, 2010 at 7:11 am
Get the current local time broken out into individual variables:
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime();
then construct a string that contains the hour, minute and second in colon-separated two-digit fields:
$hhmmss = sprintf( "%02d:%02d:%02d", $hour, $min, $sec );
To confirm that it worked, print that string:
print $hhmmss;
July 20th, 2010 at 7:11 am
Also, you don’t need to save anything after hour from the returned array with the localtime call. So you can shorten the call to
my ($sec, $min, $hour) = localtime();