Jump to content

How to convert HHMMSS format to 8:00am?


benphp

Recommended Posts

Here is one way:

 

<?php
function formatTime ( $str ) {
  $min = str_pad($str/100%100,2,'0',STR_PAD_LEFT);
  $hour = $str/100/100%100;
  return ($hour > 12)
    ? ($hour-12).':'.$min.'pm'
    : $hour.':'.$min.'am';
}
print formatTime(80000);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.