Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Converting 24 hour time back into 12 hour

by TedPride (Priest)
on Nov 08, 2004 at 05:24 UTC ( [id://405975]=note: print w/replies, xml ) Need Help??


in reply to Converting 24 hour time back into 12 hour

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
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 $hour = int (time / 3600) % 12; $hour = 12 if ! $hour; # if 0 should be 12

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://405975]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-04-24 09:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found