php时间直到特定的日期和时间

时间:2014-11-12 18:03:40

标签: php time strtotime

这是我目前的代码:

$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

2 个答案:

答案 0 :(得分:0)

要计算weekshours首先获得nowdesired 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');
}
相关问题