Convert 24 hours format to 12 hours – Javascript

alert(getTwelveFormatTime("2020/05/10 18:12:12" ));

//Convert Time By Date || hh:mm AP|PM
function getTwelveFormatTime(date) {
    var date = new Date(date);
    var hours = date.getHours();
    var minutes = date.getMinutes();
    var ampm = hours >= 12 ? 'PM' : 'AM';
    hours = hours % 12;
    hours = hours ? hours : 12; // the hour '0' should be '12'
    minutes = minutes < 10 ? '0' + minutes : minutes;
    var strTime = hours + ':' + minutes + ' ' + ampm;
    return strTime;
}

 

+1
0
+1
0
+1
0
+1
0
+1
0
+1
0
+1
1