codescracker


perl

Perl Date and Time



« Previous Tutorial Next Tutorial »


You are free to handle date and time in your perl program. The function localtime() available in perl, returns values for the current date and time if given no arguments. Here is the list of 9-elements returned by the localtime() function:

Perl Date and Time Example

Here is an example program, prints different elements returned by the function localtime():

#!/usr/local/bin/perl
 
@months_list = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
@days_list = qw(Sun Mon Tue Wed Thu Fri Sat Sun);

($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime();
print("$mday $months_list[$mon] $days_list[$wday]\n");

When the above code is executed, it will produce the following result:

18 Feb Mon

Here is another example program, also demonstrates date and time in perl:

#!/usr/local/bin/perl
 
$current_date_time = localtime();
print("Current Local Date and Time = $current_date_time\n");

Now when the above code is executed, it will produce the following result:

Above Perl Example Output:
Current Local Date and Time = Mon Feb 23 06:40:45 2015

« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test