in reply to Re: Converting 24 hour time back into 12 hour
in thread Converting 24 hour time back into 12 hour

hi,

slight correction:

sub to12h { local $_=shift; if (($_ < 0) || ($_ > 23)) { return ("$_ is not a valid hour"); } return ($_, "AM") if $_ < 12; return ($_, "PM") if $_ == 12; return ($_ -12, "PM") } for (0..23) { print join " ", to12h($_), "\n"; }

Jason L. Froebe

Team Sybase member

No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

Replies are listed 'Best First'.
Re^3: Converting 24 hour time back into 12 hour
by theorbtwo (Prior) on Nov 07, 2004 at 17:02 UTC
    Thanks.
Re^3: Converting 24 hour time back into 12 hour
by Lana (Beadle) on May 27, 2013 at 03:31 UTC
    one more correction - you have forgot to convert 24hr's 00 hours to 12AM
    sub to12h { local $_=shift; if (($_ < 0) || ($_ > 23)) { return ("$_ is not a valid hour"); } return (12, "AM") if $_ == 0; return ($_, "AM") if $_ < 12; return ($_, "PM") if $_ == 12; return ($_ -12, "PM"); } for (0..23) { print join " ", to12h($_), "\n"; }
      there is no such thing as 24:00hrs...