Getting Hour and Minute in PHP


Question

I need to get the current time, in Hour:Min format can any one help me in this.

1
55
10/7/2013 11:23:21 AM

Accepted Answer

print date('H:i');
$var = date('H:i');

Should do it, for the current time. Use a lower case h for 12 hour clock instead of 24 hour.

106
10/6/2009 2:43:30 PM

Try this:

$hourMin = date('H:i');

This will be 24-hour time with an hour that is always two digits. For all options, see the PHP docs for date().


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon