in reply to Converting 24 hour time back into 12 hour
I looked through this thread, and was amazed that nobody implemented a correct, lossless implementation. Generally, when you write a 12-hour time, you should include "AM" or "PM", because otherwise you loose information. Thus, I'm adding my solution:
sub to12h { local $_=shift; return (12, "PM") if $_==0; return ($_, "AM") if $_<=12; return ($_-12, "PM") } for (0..23) { print join " ", to12h($_), "\n"; }
Of course, if you /want/ to loose information, just use the first element of the return value.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Converting 24 hour time back into 12 hour
by jfroebe (Parson) on Nov 07, 2004 at 16:57 UTC | |
by theorbtwo (Prior) on Nov 07, 2004 at 17:02 UTC | |
by Lana (Beadle) on May 27, 2013 at 03:31 UTC | |
by Anonymous Monk on Nov 04, 2015 at 03:32 UTC |