in reply to How do I convert localtime to display 12 hr time instead of 24 hr time

my ($sec, $min, $hour, $mday, $mon, $year) = localtime($_[0]); $mon += 1; $year += 1900; $ampm = ( $hour < 12 ? 'am' : 'pm' ); $hour %= 12; $hour += 12 if !$hour; $time = sprintf("%d:%02d%s %d/%02d/%02d", $hour, $min, $ampm, $mon, $mday, $year );
or
use POSIX qw( strftime ); # Formats as "6:45pm 10/31/2008" $time = strftime('%I:%M%p %m/%d/%Y', localtime($_[0]));

Update: Added surrounding code to show other improvements and to contrast complexity with strftime version.

Replies are listed 'Best First'.
Re^2: How do I convert localtime to display 12 hr time instead of 24 hr time
by CG_man (Novice) on Nov 14, 2008 at 04:11 UTC
    Nice !! Ikegami, worked perfect, I searched every where for a converter code, thanks for the help, have a great holiday season