How to convert 24hr time to 12 hr time and configure am pm in php

It identifies the difference between AM and PM. when someone enters a time it will calculate the time in 24 hours format and then it will convert it in 12 hr format. As a result, the user can see the result as 12 hours format and based on that it will change the timestamp in am or pmtechnical analysis :date.slice(-2); // this code is used for cut the last 2 words from the time, which is AM or PM. So, it can be used for latervar stHour // For hours calculationvar stMin // For minutes calculationvar stAmPm // For AM or PM calculation

function select_time1(){
  // alert(\'timerw\');
   var date=$(\"#select_time22\").val();
  // alert(date);
   var str1 = date.slice(-2);
  var  str = date.slice(0, -2);

    var stSplit = str.split(\".\");// alert(stSplit);
    var stHour = stSplit[0];
    var stMin = stSplit[1];
    var stAmPm = str1;
    var newhr = 0;
    var ampm = \'\';
    var newtime = \'\';
    //alert(\"hour:\"+stHour+\"\\nmin:\"+stMin+\"\\nampm:\"+stAmPm); //see current values

    if (stAmPm==\'PM\' || stAmPm==\'pm\' )
    {
        if (stHour!=12)
        {
            stHour=stHour*1+12;
        }

    }else if(stAmPm==\'AM\' || stAmPm==\'am\' && stHour==\'12\'){
       stHour = stHour -12;
    }else{
        stHour=stHour;
    }
    var timenw=stHour+\'.\'+stMin

var new_timedetails=parseFloat(timenw)-parseFloat(3.00);
var new_time=new_timedetails.toFixed(2);

var netime=tConvert(new_time);
 var strne = netime.slice(-2);
 //alert(strne);
if(strne===\'AM\' || strne===\'PM\'){
    netime=netime;
}else{
    netime=netime+\'AM\';
}

     $(\"#packagetourtime\").val(netime);
}
function tConvert (time) {
  // Check correct time format and split into components
  time = time.toString ().match (/^([01]\\d|2[0-3])(.)([0-5]\\d)(.[0-5]\\d)?$/) || [time];

  if (time.length > 1) { // If time format correct

    time = time.slice (1);  // Remove full string match value
  //  alert(time);

    time[5] = +time[0] < 12 ? \'AM\' : \'PM\'; // Set AM/PM
    time[0] = +time[0] % 12 || 12; // Adjust hours
  }
   var new_time= time.join (\'\'); // return adjusted time or original string

return new_time;
    }