Tolgar
asked on
Hoe to get current time and date in Perl
Hi,
I can get the current date by using the following code:
This gives me something like this:
I would like to add the time to this result like this:
How can I do it in Perl?
I can get the current date by using the following code:
use POSIX qw(strftime);
my $reportFile = strftime "%Y%m%d", localtime;
This gives me something like this:
20120710
I would like to add the time to this result like this:
20120710_1420
How can I do it in Perl?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Second one works fine.
Here's the correct version for #1
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $time = sprintf("%d%02d%02d_%d%d", $year+1900, ++$mon , $mday, $hour, $min);
print $time;
ASKER
Thanks a lot...
Welcome :)
ASKER
Open in new window
But I was expecting this:
Open in new window
How can I fix it?