PHP: changing the time format from 15:30 to 15:30

I have a little problem with php and time format. I tried changing the time using the date () function.

$time = date('g:i a',$time); 

But the result that I get for $time=15:30:30 is 3:30 am

Ante meridiem will remain at the AM event if it is afternoon.

Thanks.

+4
source share
2 answers

Try something like this:

  $time = date("g:ia", strtotime("15:30:00")); 
+7
source

If you take from the database My past codes were

 // get the Shift times $shiftArray=array(); $num=0; $getShiftTimes=mysqli_query($link,"SELECT * FROM shift"); while ($returnShiftTimes = mysqli_fetch_array($getShiftTimes)){ $shiftArray[$num][0]=$returnShiftTimes['shift_id']; $shiftArray[$num][1]=$returnShiftTimes['start_time']; $shiftArray[$num][2]=$returnShiftTimes['end_time']; $num++; } $time = date_format(date_create($shiftArray[0][1]), 'g:i A'); 

From 14:00:00 will return 2:00 pm

+2
source

Source: https://habr.com/ru/post/1394390/


All Articles