function formatTime($hh=0,$mm=0,$ss=0,$ampm="AM"){
		
		$ampm = strtoupper($ampm);
		
		$hhUpperBound = 12;
		if($ampm == "PM"){
			$hhUpperBound--;
		}
		
		if(!( (0 <= $hh && $hh <= $hhUpperBound) && 
			  (0 <= $mm && $mm <= 60) &&
			  (0 <= $ss && $ss <= 60)	)
				){
			throw new InvalidInputException('invalid parameters');
		}
		
		if($ampm == "PM"){
			if($hh != 12){
				$hh = $hh+12;
			}
		}else if($ampm == "AM"){
			if($hh == 12){
				$hh = 0;
			}
		}else{
			throw new InvalidInputException('last parameter should be either a AM or PM in string');
		}
		if($hh < 10){
			$hh = "0".$hh;
		}
		
		if($mm < 10){
			$mm = "0".$mm;
		}
		
		if($ss < 10){
			$ss = "0".$ss;
		}
		
		$mysqlTime = $hh.":".$mm.":".$ss;
		return $mysqlTime;
	}