-1

我的问题是,当我得到例如 15 分钟的持续时间时。数据库中每小时的持续时间,这些值存储在变量中,然后将这些变量传递给 strtotime("+15 minutes") 然后它们会出错。我该如何解决这个问题?

我的代码在这里:

$custom = $book_u['custom_min'] = $row['custom_min'];
$start_time=explode(',',$row['start_time']);
while($t==0)
{
    $t=1;
    $endTime2 = strtotime("+1".$custom."minutes", strtotime($endTime));
    $starts_t[]=date('h:i a', strtotime($endTime));
    $ends_t[]=date('h:i a', $endTime2);
    //echo  date('h:i a', strtotime($endTime)).'-'.date('h:i a', $endTime2).'</br>';
    $endTime=date('h:i a', strtotime("+15 mins", $endTime2));
    if(strtotime($endTime)>strtotime($finalTime)){
        $t=1;
    }
else $t=0;
}   
4

1 回答 1

0

strtotime()函数将生成一个时间戳,该时间戳等于自 1970 年 1 月 1 日 00:00:00 UTC 以来相对于时间戳的秒数。

因此,您对函数的输入必须始终是一个至少包含日期的值。仅使用时间值会给您带来问题。

以下是如何使用该功能的示例:

$endTime = '2018-08-10 22:00:00';  //End time must be a date reference.
//Using just a time like 22:00:00 will cause you problems.

$custom = '15'; //Number of minutes
$end_t = date('h:i a', strtotime($endTime . ' +' . $custom . ' minutes'));
//Notice where the spaces are. The strtotime() part will read "2018-08-10 22:00:00 +15 minutes"

echo $end_t; //outputs "10:15 pm" 
于 2018-08-11T07:05:57.010 回答