Getting hour and minute in PHP

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

+42
php time
Oct 06 '09 at 14:26
source share
6 answers
print date('H:i'); $var = date('H:i'); 

Must do this, within the current time. Use lowercase h for 12 hour hours instead of 24 hours.

+82
Oct 06 '09 at 14:28
source share
— -

Try the following:

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

It will be a 24-hour time with an hour that always consists of two digits. For all options, see PHP Docs for Date () .

+16
Oct. 06 '09 at 2:30 p.m.
source share
 print date('H:i'); 

You must set the correct time zone in php.ini .

Look for these lines:

 [Date] ; Defines the default timezone used by the date functions ;date.timezone = 

It will be something like:

 date.timezone ="Europe/Lisbon" 

Remember to restart the web server.

+9
Oct 06 '09 at 15:11
source share

Another way to solve the time zone problem, if you want to set the default time zone for the whole script for the certian time zone, use date_default_timezone_set() , then use one of the supported time zones .

+2
Oct 06 '09 at 21:34
source share

When referring to your comment that you need your current time, and not the system time, you will have to configure it yourself, there are 3600 seconds per hour (device timestamps are used), so use this. for example, if your system time was one hour lower:

$ time = date ('H: i', time () + 3600);

+1
Oct 06 '09 at 14:40
source share
 function get_time($time) { $duration = $time / 1000; $hours = floor($duration / 3600); $minutes = floor(($duration / 60) % 60); $seconds = $duration % 60; if ($hours != 0) echo "$hours:$minutes:$seconds"; else echo "$minutes:$seconds"; } get_time('1119241'); 
+1
Dec 05 '15 at 10:25
source share



All Articles