<?php
$dtnext = "";
$dt = "";
$nexttime = "";
$tm = strtotime($strStarttime);
$tm = $tm + $strStarttime * 60;
//echo $tm."<br>\n";
//$dt = date('H:i', $tm);

for($j = 1; $j <= $strInquiryCount; $j++) {
if( $j == 1){
$dt = date('H:i', $tm);
$nexttime = $dt;
echo "<tr width=\"238\">\n\r<td width=\"238\">".$strStarttimeTmp."-".$dt."</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r</tr>";
}else{
echo "<br>".$j.":".$nexttime."<br>";
$tm = strtotime($nexttime);
$tm = $tm + $nexttime * 60;
//echo $tm."<br>\n";
$dtnext = date('H:i', $tm);
echo $j."--".$nexttime."++".$tm."++".$dtnext."<br>\n";
echo "<tr width=\"238\">\n\r<td width=\"238\">".$nexttime."-".$dtnext."</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r</tr>";
$nexttime = $dtnext;
$tm = "";
}
}
 ?>

解决方案 »

  1.   

    $tm = strtotime($strStarttime); 是系统的当前时间。
    你的程序运行10秒,第一个和最后一个就相差10秒。试试 $tm = mktime(date("H:i"));
      

  2.   

    $strStarttime  的初始值是什么?
      

  3.   

    回复楼上的
    $strStarttime = 15:00
      

  4.   

    为什么要有 $tm = $tm + $nexttime * 60;
    你是打算每过一个整点就增加一分钟间隔时间吗?
      

  5.   

    经过我的测试 问题出在了$tm = $tm + $strStarttime * 60;
     $tm = $tm + $nexttime * 60;如果我在这里直接用 $tm=$tm+900; 的话 结果就没有任何问题
      

  6.   


    <?php
    $strStarttime = "15:00";
    for($i=0;$i<20;$i++)
    {
    $tm = strtotime($strStarttime);
    $dt = date('H:i', $tm);
    $tm = $tm + $strStarttime * 60;
    $strStarttime=date('H:i',$tm);
    echo $dt." ".$tm." ".$strStarttime." ".($strStarttime*60).PHP_EOL;
    }
    运行结果
    15:00 1307949300 15:15 900
    15:15 1307950200 15:30 900
    15:30 1307951100 15:45 900
    15:45 1307952000 16:00 960
    16:00 1307952960 16:16 960
    16:16 1307953920 16:32 960
    16:32 1307954880 16:48 960
    16:48 1307955840 17:04 1020
    17:04 1307956860 17:21 1020
    17:21 1307957880 17:38 1020
    17:38 1307958900 17:55 1020
    17:55 1307959920 18:12 1080
    18:12 1307961000 18:30 1080
    18:30 1307962080 18:48 1080
    18:48 1307963160 19:06 1140
    19:06 1307964300 19:25 1140
    19:25 1307965440 19:44 1140
    19:44 1307966580 20:03 1200
    20:03 1307967780 20:23 1200
    20:23 1307968980 20:43 1200可以看每循环四次的时候  $strStarttime * 60 就会多60
    所以往后都会出问题
      

  7.   


    <?php
            $dtnext = "";
            $dt = "";
            $nexttime = "";
            $tm = strtotime($strStarttime);
            $tm = $tm + $strStarttime * 60;  //这里是用15:00 乘以60 结果是900
            //echo $tm."<br>\n";
            //$dt = date('H:i', $tm);
                
            for($j = 1; $j <= $strInquiryCount; $j++) {
                if( $j == 1){
                    $dt = date('H:i', $tm);  //这里dt是15:15
                    $nexttime = $dt;  //nexttime是 15:15
                    echo "<tr width=\"238\">\n\r<td width=\"238\">".$strStarttimeTmp."-".$dt."</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r</tr>";
                }else{
                    echo "<br>".$j.":".$nexttime."<br>";
                    $tm = strtotime($nexttime);
                    $tm = $tm + $nexttime * 60; //你这里用15:15 乘 60 往后就会出问题了 而且越循环这个数值越大 所以时间就会增加.
                    //echo $tm."<br>\n";
                    $dtnext = date('H:i', $tm);
                    echo $j."--".$nexttime."++".$tm."++".$dtnext."<br>\n";
                    echo "<tr width=\"238\">\n\r<td width=\"238\">".$nexttime."-".$dtnext."</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r<td width=\"238\">预约</td>\n\r</tr>";
                    $nexttime = $dtnext;
                    $tm = "";
                }
                        }
     ?>