Reputation: 6511
I would really love some help with this.
Currently when I use the following PHP, my output is 02:42. What I would like is 14:42.
<?php
date_default_timezone_set('Europe/London');
echo date("h:i",time());
?>
Also, is it possible to then use the converted time value to create a conditional statement to say if greater than 10am, do this.
Many thanks for any pointers
Upvotes: 1
Views: 2059
Reputation: 837
This will convert to 24 hours clock to 12 hours clock
$date='17:29';
echo date ('g:i a',strtotime($date));
output: 5:29 pm
This will convert to 12 hours clock to 24 hours clock
$date='5:29';
echo date ('H:i',strtotime($date));
output: 17:29
Upvotes: 0
Reputation: 65332
echo date("H:i",time());
Will give you 24-based hours.
For the second Problem you could use:
if(date("a") == "pm" OR date("g") > 10){ ... }
Upvotes: 5
Reputation: 10229
Use one of these: G - 24 hour c (0-23) H - 2 digit 24 hour (00-23)
echo date("H:i", time());
Also to check
$hour = date("H", time());
if($hour > 10)
{
//do stuff
}
Upvotes: 3
Reputation: 182
I think all you need to do is change the lower case h into an upper case H
all the formats you can use are here http://php.net/manual/en/function.date.php
Upvotes: 2
Reputation: 2371
Use "H:i"
for 24h time.
https://www.php.net/manual/en/function.date.php
Upvotes: 9