Thursday, December 3, 2009

localtime: How to tell local time in perl

localtime():
It's a function in perl which converts a time as returned by the time function to a 9-element list with the time analyzed for the local time zone. Typically used as follows:
0: sec, 1: min, 2: hour, 3:mDay, 4:mon, 5:year, 6:wDay, 7:yDay, 8:isDst

my $curTime = time();
my ( $sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($curTime);
$year is the number of years from 1900, so for 2009 it will be 109.
so you will have to 1900 in $ year.
$year += 1900;


print "$mday/$mon/$year --- $hour:$min:$sec";

my $ltime = localtime();
print $ltime; It will print as "Thu Dec  3 00:43:57 200"

No comments:

Post a Comment