Reputation: 12897
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"?
Upvotes: 5
Views: 4861
Reputation: 19220
//Call this once before the 1st date/time operation
date_default_timezone_set('Europe/Zurich');
echo date('H:i', strtotime('6:15pm'));
Upvotes: 1
Reputation: 625057
You can do this with strtotime()
:
echo date('H:i', strtotime('6.:15pm'));
Upvotes: 2
Reputation: 268344
I would suggest using strtotime()
with date()
:
print date("H:i", strtotime("6:15pm"));
Upvotes: 11