in reply to Time transformation
or similar. Then you just create a subroutine to do the conversion. I'd probably write it like this$xcltime=convert_time($xcltime); $xcltime2=convert_time($xcltime2);
Another issue is that your code inserts no space for AM, but an html nonbreaking space for PM. I've inserted the space in both cases, but you could change that if you really wanted to.sub convert_time{ my ($time)=shift; my ($h, $m, $s) = $time =~ /^(\d\d?):(\d\d?):(\d\d?)$/; my ($suffix); if ($h > 12){ $h-=12; $suffix=" PM"; } elsif ($h == 0) { $h = 12; $suffix=" AM"; } else { $suffix=" AM"; } return "$h:$m:$s$suffix"; }
I've also included a fix for if the time is "00:15:17" or such, converting it to "12:15:17 AM".
|
|---|