benphp Posted April 24, 2008 Share Posted April 24, 2008 Trying to figure this out, and I know there's a simple way. I have some times: 80000 = 8:00am, that is, 8th hour, 00 minutes, and 00 seconds. How do I convert it to "8:00am"? Thanks! Link to comment https://forums.phpfreaks.com/topic/102772-how-to-convert-hhmmss-format-to-800am/ Share on other sites More sharing options...
rhodesa Posted April 24, 2008 Share Posted April 24, 2008 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); ?> Link to comment https://forums.phpfreaks.com/topic/102772-how-to-convert-hhmmss-format-to-800am/#findComment-526430 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.