[英]How to get Current time in php like 5:00 pm?
How to get Current time in php like 5:00 pm ? 如何在下午5点获取PHP的当前时间? I have problem in getting time in php like 5:00 pm because I have to create a decision for example
我有时间在下午5点在PHP中获取时间,因为我必须创建一个例子
<?php
$current_time = ("h:i a");
if($current_time > "5:00 pm"){
echo 'Hide';
}else{
echo 'show';
}
?>
I want to show the 'hide' text after 5:00 pm. 我希望在下午5点之后显示“隐藏”文字。
anyone knows? 有谁知道?
Thanks for the help. 谢谢您的帮助。
Very Much appreciated. 非常感谢。
Use the 24-hour-system and you won't have any problems: if(date('G') > 17)
使用24小时制,您将不会遇到任何问题:
if(date('G') > 17)
G 24-hour format of an hour without leading zeros 0 through 23
G小时24小时格式,没有0到23的前导零
Using your specific example, you cannot compare human time, only computer time. 使用您的具体示例,您无法比较人类时间,只能比较计算机时间。 This is why strtotime is useful.
这就是strtotime有用的原因。
http://php.net/manual/en/function.strtotime.php http://php.net/manual/en/function.strtotime.php
<?php
$current_time = time();
$my_time=strtotime( date('Y-m-d') . ' 5:00 pm' );
//uncomment if you want to check in the morning as well
//$my_earlytime=strtotime( date('Y-m-d') . ' 8:00 am' );
//uncomment this line if you want to check in the morning as well
//if ( $current_time > $my_time || $current_time < $my_earlytime ){
//comment this line if you want to check in the morning as well
if ( $current_time > $my_time ) {
//after 5:00pm it will hide
//hides before 8am if you check early time
echo 'Hide';
}
else {
//after midnight it will go back to show
//unless you also check the early time
echo 'show';
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.