Dec 12, 2000, 5:05 PM
Post #1 of 6
There are many different methods to getting the data & time in perl, if your looking to just get the full date and time, you could do this:
How do I get the date and time?
$date_time = localtime;
Tue Dec 12 16:23:58 2000
To get each element of localtime and make your own format, just use this code:
@date_time = localtime;
$date = "@date_time";
($sec, $min, $hours, $mday, $month, $year, $wday, $yday, $isdst) = split(/\s/, $date);
$year += 1900;
All that last line does is bring the year up to 2000, since it's the year 2000 right now.
Other variables like the $month, start at 0, being January, to turn these numbers into the name of the months, you could make an array of months in the correct order and just call on the array value to print the month's name. Like so:
(@names) = ('January','February','March','April','May','June','July','August','September','October','November','December');
$month_name = "$names[$month]";
Since this was written in December.
I have attached a small txt file including a chart of the variables and there meanings to help you.
Also, you can use "gmtime" instead of "localtime" to get your date's and time's based on GMT time.
That concludes getting the date and time in perl.