Forum Moderators: coopster

Message Too Old, No Replies

converting over to 24 hr fornat

         

branmh

2:03 am on Aug 18, 2003 (gmt 0)

10+ Year Member



I would like to convert a varible (7 PM) into a 24 HR (19) format?

dmorison

7:12 am on Aug 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The quickest way to do this by a country mile would be a conversion table:

$t["1 AM"] = "01";
$t["2 AM"] = "02";
$t["3 AM"] = "03";


etc. etc.

and then simply use:


$newtime = $t[$oldtime];

You could use string split functions and some maths, but it would compile into way more code than doing a conversion table.

branmh

12:16 pm on Aug 18, 2003 (gmt 0)

10+ Year Member



Is there anyway to convert this over to PHP from PERL:
$a = '7 PM';
$a =~ s/\b(\d\d?)\s+([AP]M\b)/$2 eq 'PM'? $1+12 : $1/eg;
print "$a\n";