Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php 12 hr format to 24hr format time converting

Tags:

php

time

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"?

like image 615
Andromeda Avatar asked Dec 31 '09 07:12

Andromeda


2 Answers

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

print date("H:i", strtotime("6:15pm"));
like image 161
Sampson Avatar answered Sep 23 '22 02:09

Sampson


You can do this with strtotime():

echo date('H:i', strtotime('6.:15pm'));
like image 29
cletus Avatar answered Sep 23 '22 02:09

cletus