idiot on perl idiot on perl - 4 months ago 26
Perl Question

How to format local time to mm/dd/yyyy HH:MM:SS AM/PM in Perl

I need to convert the local time to exact format as

mm/dd/yyyy HH:MM:SS AM/PM
.

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();

Answer

By using strftime of POSIX module you can get the desire result:

use POSIX qw/strftime/;
print strftime('%d-%m-%Y %I:%M:%S %p',localtime);
Comments