Getting Hour and Minute in PHP

2019-01-14 00:09发布

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

标签: php time
7条回答
走好不送
2楼-- · 2019-01-14 00:21
print date('H:i');

You have to set the correct timezone 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"

Don't forget to restart your webserver.

查看更多
【Aperson】
3楼-- · 2019-01-14 00:23

You can use the following solution to solve your problem:

echo date('H:i');
查看更多
混吃等死
4楼-- · 2019-01-14 00:30

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().

查看更多
迷人小祖宗
5楼-- · 2019-01-14 00:31
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.

查看更多
Lonely孤独者°
6楼-- · 2019-01-14 00:38

In addressing your comment that you need your current time, and not the system time, you will have to make an adjustment yourself, there are 3600 seconds in an hour (the unit timestamps use), so use that. for example, if your system time was one hour behind:

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

查看更多
闹够了就滚
7楼-- · 2019-01-14 00:40
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');
查看更多
登录 后发表回答