这是我目前的代码:
$nm = strtotime('next monday 19:30');
$nt = strtotime('next wednesday 19:30');
$ns = strtotime('next Saturday 09:00');
它有点有效,但是我们说这是星期三它不会告诉我类似X小时的事情,它会告诉我1周X小时。
我该如何解决这个问题?
您可以在此处查看现场演示:http://www.forumalliance.x10.mx/troll.php
答案 0 :(得分:0)
要计算weeks
和hours
首先获得now
和desired time
之间的时间间隔。然后将interval
除以七天等效秒以获得第n周和mod
以获得休息时间。例如:
$nm = strtotime('next monday 19:30');
$interval = $nm - time();
$week = floor($interval / (7 * 24 * 60 * 60));
$hour = floor(($interval % (7 * 24 * 60 * 60)) / 3600);
echo $week . ' week ' . $hour . ' hour(s)';
答案 1 :(得分:0)
$day = date('l');
$hour = date('H');
$min = date('i');
if ($hour <= 19 and $min < 30 and $day == "Monday") {
$nm = strtotime('this monday 19:30');
}else{
$nm = strtotime('next monday 19:30');
}
if ($hour <= 19 and $min < 30 and $day == "Wednesday") {
$nt = strtotime('this wednesday 19:30');
}else{
$nt = strtotime('next wednesday 19:30');
}
if ($hour <= 09 and $min < 00 and $day == "Saturday") {
$ns = strtotime('this saturday 09:00');
}else{
$ns = strtotime('next saturday 09:00');
}