sub-routine: gettime();
Over the years working as a systems administrator I have a large sub-routine collection on my belt. One that I use quite frequently is gettime();. This is a simple routine someone in my group wrote to return a nicely formatted timestamp. It is use mostly for logging and such.
sub gettime () {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900;
$mon += 1;
my $retval = sprintf("$year\-%02d\-%02d %02d:%02d:%02d",$mon,$mday,$hour,$min,$sec);
return $retval;
}
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900;
$mon += 1;
my $retval = sprintf("$year\-%02d\-%02d %02d:%02d:%02d",$mon,$mday,$hour,$min,$sec);
return $retval;
}
Example:
returns:
2009-05-27 07:18:43
Popularity: 12% [?]
Categories: Perl, Programming