它剩下多长时间了?php +约会

Joh*_*ohn 3 php date

//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);
Run Code Online (Sandbox Code Playgroud)

我试图输出多长时间,直到用户被取消...年月,日,小时,分钟和秒......但这给了我一些奇怪的结果..

Cze*_*ogy 5

您应该查看有关如何使用日期/时间功能的手册.

首先,而不是

$current_time + strtotime('+1 minute')
Run Code Online (Sandbox Code Playgroud)

使用

strtotime('+1 minute', $current_time);
Run Code Online (Sandbox Code Playgroud)

(见手册strtotime).

其次,date函数返回一个字符串.在大多数情况下,减去两个字符串并不是很有用.

if ($unbanned_time > $current_time) {
  $th1is = $unbanned_time - $current_time;
  echo $th1is/3600 . ' hours';
}
Run Code Online (Sandbox Code Playgroud)

这将以小时为单位输出剩余时间,但有许多可用的功能可以产生更好的格式(或者您可以自己编写一个).