tags:

views:

169

answers:

3

I have a string like "6:15pm". Is there any function in PHP which will convert it directly to 24 hr format. ie to "18:15"?

+4  A: 

I would suggest using strtotime() with date():

print date("H:i", strtotime("6:15pm"));
Jonathan Sampson
+1  A: 

You can do this with strtotime():

echo date('H:i', strtotime('6.:15pm'));
cletus
+1  A: 
//Call this once before the 1st date/time operation
date_default_timezone_set('Europe/Zurich');

echo date('H:i', strtotime('6:15pm'));
Ivan Krechetov