php date函数返回错误的值

I'm attempting to convert user inputted 12 hour time to 24 hour time in php so I can better sort and report on it. below code returns 16:00 no matter what is entered.

$starttime1 = date("H:i", strtotime("$starttime"));

in this instance what is being fed to $starttime is g:i:s:A or 4:00:00:AM

In the last hour of searching it appears to be an issue with the date function not getting the right information, so I tried DateTime::createFromFormat

$starttime = DateTime::createFromFormat('g:i:s:A', $starttime);
  $starttime1 = $starttime->format( 'H:i');

generates null

I feel like I'm doing something stupid.. need to take a break from coding and will keep googling, but hoping someone can point me in the right direction.

That's probably because you have a :AM in your time string. It should be a space instead of the :

$time = '4:00:00 AM';
$time = date('H:i', strtotime($time));

And the var_dump of $time would be:

string(5) "04:00"