Php 在两次之间均匀分布值

Php 在两次之间均匀分布值,php,datetime,Php,Datetime,我有以下代码。我需要在两次之间均匀分布值:现在+20分钟到15:30。下面的代码是一个循环的一部分,为了简洁起见,我没有包括这个循环 $numlines = count($data); $calltime = date('U', strtotime('+20 minutes'); $to = date('U', strtotime('15:30')); $from = $calltime; $diffinsec = $to - $from; $apptseparation = ceil(

我有以下代码。我需要在两次之间均匀分布值:现在+20分钟到15:30。下面的代码是一个循环的一部分,为了简洁起见,我没有包括这个循环

$numlines = count($data);

$calltime = date('U', strtotime('+20 minutes');

$to = date('U', strtotime('15:30'));
$from = $calltime;

$diffinsec = $to - $from;

$apptseparation = ceil($diffinsec / $numlines);

$calltime = date('H:i', strtotime('+' . $apptseparation . ' seconds', $calltime);
我在这里要做的是将当前时间加上20分钟,将其转换为Unix历元,然后从当天的15:30减去它。结果应该是两次之间的秒数

然后我想用输入文件中的总行数除以秒数,得到每个值之间的总秒数。最后,我想将这个数字添加到现有的$calltime变量中,这样循环的每次迭代都会添加新的时间


不过,我所拥有的并不管用。日期数学总是让我困惑,在PHP中更是如此。如果你需要更多的信息,请告诉我

那么,你得到了什么样的结果?你期望得到什么样的结果? 如果我能很好地理解以下内容,则此代码似乎有效:
    $calltime = strtotime('+20 minutes');
    $from = $calltime;
    $to = strtotime('15:30');

    $diffinsec = $to - $from;
    if ( $diffinsec < 0 ) { // If it is 18:04 per example
        $diffinsec *= -1;
    }
    $apptseparation = ceil($diffinsec / $numlines);

    $calltime = date('H:i', strtotime('+'.$apptseparation.' seconds', $calltime));
$calltime=strottime(“+20分钟”);
$from=$calltime;
$to=标准时间('15:30');
$diffinset=$to-$from;
if($diffinse<0){//如果每个示例的值为18:04
$diffinse*=-1;
}
$apptseparation=ceil($diffinsite/$numlines);
$calltime=date('H:i',strottime('+.$apptseparation.'seconds',$calltime));

FYI:
date('U',strotime(…)
==
strotime(…)
。您不需要将UNIX时间戳转换为UNIX时间戳。啊,您知道吗?我打赌这是个负面问题。我甚至都没想过要纠正这一点。谢谢