I believe this should do what you want:
function formatDateTime($date = 'now', $format = '%l:%M %P') {
$ret = strftime($format, strtotime($date));
return str_replace(array('am', 'pm', ':00'), array('a.m','p.m', ''), $ret);
}
Example usage:
echo formatDateTime('1385914593');
echo formatDateTime('08:00:04 AM');
echo formatDateTime('13:26:04');
Output:
5:30 a.m
8 a.m
1:26 p.m