in reply to Time transformation
#! /usr/bin/perl use strict; use warnings; my $xcltime = "19:45:34"; # It should print 7:45 PM my $xcltime2 = "23:35:14"; # It should print 11:35 PM my ($h1,$m1,$s1) = split /:/, $xcltime; print "$h1,$m1,$s1\n"; my ($h2,$m2,$s2) = split /:/, $xcltime2; print "$h2,$m2,$s2\n"; $xcltime =sprintf("%02s:%02s%s", $h1 % 12, $m1, ($h1 > 12) ? "PM" : "A +M" ); $xcltime2=sprintf("%02s:%02s%s", $h2 % 12, $m2, ($h2 > 12) ? "PM" : "A +M" ); print "$xcltime - $xcltime2"; __END__ 19,45,34 23,35,14 07:45PM - 11:35PM
|
|---|