I need to get the current time, in Hour:Min format can any one help me in this.
我需要得到当前的时间,以小时为单位:最小格式,谁能在这方面帮助我。
6 个解决方案
#1
90
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.
应该这样做,对于当前时间。用小写h表示12小时,而不是24小时。
#2
17
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().
这将是24小时的时间,一个小时的时间总是两位数。对于所有选项,请参见PHP文档中的date()。
#3
9
print date('H:i');
You have to set the correct timezone in php.ini
.
您必须在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.
不要忘记重启你的网络服务器。
#4
2
Another way to address the timezone issue if you want to set the default timezone for the entire script to a certian timezone is to use date_default_timezone_set()
then use one of the supported timezones.
另一种解决时区问题的方法是,如果您想将整个脚本的默认时区设置为一个指定时区,那么使用date_default_timezone_set(),然后使用一个受支持的时区。
#5
1
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:
在处理您需要当前时间而不是系统时间的评论时,您必须自己进行调整,每小时有3600秒(使用单位时间戳),所以请使用它。例如,如果您的系统时间落后一小时:
$time = date('H:i',time() + 3600);
$time =日期('H:i',time() + 3600);
#6
1
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
90
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.
应该这样做,对于当前时间。用小写h表示12小时,而不是24小时。
#2
17
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().
这将是24小时的时间,一个小时的时间总是两位数。对于所有选项,请参见PHP文档中的date()。
#3
9
print date('H:i');
You have to set the correct timezone in php.ini
.
您必须在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.
不要忘记重启你的网络服务器。
#4
2
Another way to address the timezone issue if you want to set the default timezone for the entire script to a certian timezone is to use date_default_timezone_set()
then use one of the supported timezones.
另一种解决时区问题的方法是,如果您想将整个脚本的默认时区设置为一个指定时区,那么使用date_default_timezone_set(),然后使用一个受支持的时区。
#5
1
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:
在处理您需要当前时间而不是系统时间的评论时,您必须自己进行调整,每小时有3600秒(使用单位时间戳),所以请使用它。例如,如果您的系统时间落后一小时:
$time = date('H:i',time() + 3600);
$time =日期('H:i',time() + 3600);
#6
1
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');