Andromeda
Andromeda

Reputation: 12897

php 12 hr format to 24hr format time converting

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

Answers (3)

Ivan Krechetov
Ivan Krechetov

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

cletus
cletus

Reputation: 625057

You can do this with strtotime():

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

Upvotes: 2

Sampson
Sampson

Reputation: 268344

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

print date("H:i", strtotime("6:15pm"));

Upvotes: 11

Related Questions