我已将此文件存储在DATETIME类型的数据库中 考虑它的价值: 2017-12-14 16:17:21
这是我的程序逻辑。我想检查是否过了72小时其他回声你需要等待48小时22分55秒。例如。
$row = $res->fetch_assoc();
$last_dl = $row['last_dl'];
// To seconds from 1970
$last_dl = strtotime($last_dl); //120
$seventy_two_hours_in_seconds = 60 * 60 * 72;
if (time() > ($last_dl + $seventy_two_hours_in_seconds)) {
echo "72 Passed";
} else {
echo "You need to wait: " . date('H/h i/m s/s',mktime(0, 0, ($last_dl + $seventy_two_hours_in_seconds) - time()));
}
逻辑有什么问题。因为它显示出更少的时间。
答案 0 :(得分:1)
您可以计算等待的秒数,以及以小时,分钟和秒为单位的时间:
<?php
$row = $res->fetch_assoc();
$last_dl = $row['last_dl'];
// To seconds from 1970
$last_dl = strtotime($last_dl); //120
$seventy_two_hours_in_seconds = 60 * 60 * 72;
if (time() > ($last_dl + $seventy_two_hours_in_seconds)) {
echo "72 Passed";
} else {
$wait = date('U', $last_dl + $seventy_two_hours_in_seconds) - date('U'); // seconds for wait
$hours = floor($wait /3600);
$min = floor(($wait / 60) % 60);
$sec = $wait % 60;
echo "You need to wait: ". $hours. ':'. $min.':'.$sec ."\n";
}
http://sandbox.onlinephpfunctions.com/code/08477cd78c82dfe2b4a5c5f4aee6414866999a8c