in reply to Converting 24 hour time back into 12 hour
No point doing extra work computing AM/PM if you don't need them, and if you do, it's easy to determine AM/PM by comparing $hour and $shour. Or if all you want is the hour and you don't care about the rest at all:my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(t +ime); my $shour = ($hour > 11 ? $hour - 12 : $hour); $shour = 12 if ! $shour; # if 0 should be 12
my $hour = int (time / 3600) % 12; $hour = 12 if ! $hour; # if 0 should be 12
|
|---|