简体   繁体   中英

increment and decrement the time and loop in codeigniter

if my time is 12:00am and i want to display as

11:30pm 11:45pm 12:00am 12:15am 12:30am please help me for getting this iam learning now

$i= $_GET['time'] 

$start=strtotime($i);
$end=strtotime('2:30');

for ($i=$start;$i<=$end;$i = $i + 15*60) {
   echo date('H:i A',$i).'<br>';
}

iam getting result as

00:00 AM

00:15 AM

00:30 AM

00:45 AM

01:00 AM

01:15 AM

01:30 AM

01:45 AM

02:00 AM

02:15 AM

02:30 AM

use

echo date('h:i a',$i).'<br>';

for more details use reference php date time class

Please try this

<?php

$i= '12:00 am';
$start=strtotime("-30 minutes" , strtotime($i));
$end=strtotime("+30 minutes" , strtotime($i));

for ($i=$start;$i<=$end;$i = $i + 15*60) 
{
    echo "<br/>";
   echo date('h:i A',$i).'<br>';
}

?>
<?php

$time_interval = $time->reservation_time_interval; //if 15 min
$dateTime = new DateTime($_GET['date'].$_GET['time']); //if 12:00 am
$dateTime->modify("-$time_interval min");
$date_pre= $dateTime->format('Y-m-d');
$time_pre= $dateTime->format('h:i a');

$dateTime = new DateTime($time_pre);
$dateTime->modify("-$time_interval min");
$time_pre1= $dateTime->format('h:i a');

$dateTime = new DateTime($_GET['time']);
$dateTime->modify("$time_interval min");
$time_post= $dateTime->format('h:i a');

$dateTime = new DateTime($time_post);
$dateTime->modify("$time_interval min");
$time_post1= $dateTime->format('h:i a');

echo $time_pre;echo $time_pre1;echo $time_post;echo $time_post;
?>

when u print, u will get this= 11:30pm 11:45pm 12:15am 12:30am

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM