我想以15分钟的间隔抽出时间。我希望我的程序打印当前时间的15分钟,30分钟,45分钟,00分钟。假设时间是下午1:00我想要打印15分钟。 15分钟后应该打印下午1:15。
这是我的代码,它的工作正常,但显示30秒后的时间。
请检查。
<?php
//$getdate=date('Y-m-d');
$timezone = new DateTimeZone("Asia/Kolkata" );
$date = new DateTime();
$date->setTimezone($timezone );
$time= $date->format( 'H:i:s A ' );
$getdate= $date->format( 'Y-m-d' );
$newarrdate=explode('-',$getdate);
$getdatefromarr=$newarrdate[0]."-".$newarrdate[1]."-".$newarrdate[2];
$gettime=explode(':',$time);
$hour=$gettime[0];
$amorpm=substr($gettime[2],3,2);
if($amorpm=="AM")
{
$chamorpm="A.M";
}
else
{
$chamorpm="P.M";
}
$currentitme=$hour.":".$gettime[1]." ".$chamorpm;
$minutearr=array(00,15,30,45);
$getarr1=array(01,02,03,04,05,06,07,08,09,10,11,12,13,14);
$getarr2=array(16,17,18,19,20,21,22,23,24,25,26,27,28,29);
$getarr3=array(31,32,33,34,35,36,37,38,39,40,41,42,43,44);
$getarr4=array(46,47,48,49,50,51,52,53,54,55,56,57,58,59);
$minutearr1=array(00=>00,01=>01,02=>02,03=>03,04=>04,05=>05,06=>06,07=>07,08=>8,09=>9,10=>10,11=>11,12=>12,13=>13,14=>14);
$minutearr2=array(15=>00,16=>01,17=>02,18=>03,19=>04,20=>05,21=>06,22=>07,23=>8,24=>9,25=>10,26=>11,27=>12,28=>13,29=>14);
$minutearr3=array(30=>00,31=>01,32=>02,33=>03,34=>04,35=>05,36=>06,37=>07,38=>8,39=>9,40=>10,41=>11,42=>12,43=>13,44=>14);
$minutearr4=array(45=>00,46=>01,47=>02,48=>03,49=>04,50=>05,51=>06,52=>07,53=>8,54=>9,55=>10,56=>11,57=>12,58=>13,59=>14);
$valtime=$gettime[1];
$changearr=array(0,1,2,3,4,5,6,7,8,9);
$makerarry=array(00,01,02,03,04,05,06,07,08,09);
if(in_array($gettime[1],$minutearr))
{
$querytitme=$hour.":".$gettime[1]." ".$chamorpm;
}
else if(in_array($gettime[1],$getarr1))
{
if(in_array($valtime,$makerarry))
{
$getmaketime=substr($valtime,1);
}
else
{
$getmaketime=$valtime;
}
$caltime=$gettime[1]-$minutearr1[$getmaketime];
if(in_array($caltime,$changearr))
{
$newtime="0".$caltime;
}
$querytitme=$hour.":".$newtime." ".$chamorpm;
if($hour>=13)
{
$drawtimehour=$hour-12;
$gethourfromdraw=$drawtimehour.":".$newtime." ".$chamorpm;
}
else
{
$drawtimehour=$hour;
$gethourfromdraw=$drawtimehour.":".$newtime." ".$chamorpm;
}
}
else if(in_array($gettime[1],$getarr2))
{
$caltime=$gettime[1]-$minutearr2[$valtime];
$querytitme=$hour.":".$caltime." ".$chamorpm;
if($hour>=13)
{
$drawtimehour=$hour-12;
$gethourfromdraw=$drawtimehour.":".$caltime." ".$chamorpm;
}
else
{
$drawtimehour=$hour;
$gethourfromdraw=$drawtimehour.":".$caltime." ".$chamorpm;
}
}
else if(in_array($gettime[1],$getarr3))
{
$caltime=$gettime[1]-$minutearr3[$valtime];
$querytitme=$hour.":".$caltime." ".$chamorpm;
if($hour>=13)
{
$drawtimehour=$hour-12;
$gethourfromdraw=$drawtimehour.":".$caltime." ".$chamorpm;
}
else
{
$drawtimehour=$hour;
$gethourfromdraw=$drawtimehour.":".$caltime." ".$chamorpm;
}
}
else if(in_array($gettime[1],$getarr4))
{
$caltime=$gettime[1]-$minutearr4[$valtime];
$querytitme=$hour.":".$caltime." ".$chamorpm;
if($hour>=13)
{
$drawtimehour=$hour-12;
$gethourfromdraw=$drawtimehour.":".$caltime." ".$chamorpm;
}
else
{
$drawtimehour=$hour;
$gethourfromdraw=$drawtimehour.":".$caltime." ".$chamorpm;
}
}
if($hour>=13 && $hour<20)
{
$drawhour=$hour-12;
if($gettime[1]>=0 && $gettime[1]<=14)
{
$drwatime=$drawhour.":"."15"." ".$chamorpm;
}
else if($gettime[1]>=16 && $gettime[1]<=29)
{
$drwatime=$drawhour.":"."30"." ".$chamorpm;
}
else if($gettime[1]>=31 && $gettime[1]<=44)
{
$drwatime=$drawhour.":"."45"." ".$chamorpm;
}
else if($gettime[1]>=44 && $gettime[1]<=59)
{
$getnexthour=$drawhour+1;
$drwatime=$getnexthour.":"."00"." ".$chamorpm;
}
}
else if($hour>=22 )
{
$drwatime="Closed";
}
else
{
$drawhour=$hour;
if($gettime[1]>=0 && $gettime[1]<=15)
{
$drwatime=$drawhour.":"."15"." ".$chamorpm;
}
else if($gettime[1]>=16 && $gettime[1]<=30)
{
$drwatime=$drawhour.":"."30"." ".$chamorpm;
}
else if($gettime[1]>=31 && $gettime[1]<=45)
{
$drwatime=$drawhour.":"."45"." ".$chamorpm;
}
else if($gettime[1]>=46 && $gettime[1]<=60)
{
$getnexthour=$drawhour+1;
if($getnexthour==12)
{
$disamorpm="P.M";
}
else
{
$disamorpm=$chamorpm;
}
$drwatime=$getnexthour.":"."00"." ".$disamorpm;
}
}
此程序还会在下次打印。例如下午1点它也打印1:15。但我需要帮助打印当前时间15分钟。