How to convert 24 hour format to 12 hour format time in php?

This post converting 24 hour format to 12 hours format time.

1. Code

    <?php 
	function convertTime24hTo12h($time){
		$time = DATE("g:i:s a", STRTOTIME($time));
		return $time;
	}
	$str = "22:22:33";
	
	echo(convertTime24hTo12h($str));
    ?> 

2. Example:

Input:

"22:22:33"

Output:

10:22:33 pm