//Example data
$current_time = 1318075950;
$unbanned_time = $current_time + strtotime('+1 minute');
if ($unbanned_time > $current_time) {
$th1is = date('Y-m-d H:i:s', $unbanned_time) - date('Y-m-d H:i:s', $current_time);
echo date('Y-m-d H:i:s', $th1is);
我试图输出用户被解除封禁之前的时间……年月、日、小时、分钟和秒……但这给了我一些奇怪的结果……
最佳答案
您应该查看有关如何使用日期/时间函数的手册。
首先,而不是
$current_time + strtotime('+1 minute')
使用
strtotime('+1 minute', $current_time);
(参见 strtotime
上的手册)。
其次,date
函数返回一个字符串。在大多数情况下,减去两个字符串并不是很有用。
if ($unbanned_time > $current_time) {
$th1is = $unbanned_time - $current_time;
echo $th1is/3600 . ' hours';
}
这将以小时为单位输出剩余时间,但有许多可用的函数可以生成更好的格式(或者您可以自己编写一个)。
关于php - 还剩多少时间? PHP + 日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7696715/