JSFiddle - React, Tailwind, and code Playground

by bnson

HTML

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Convert to 24 hour</button>

<script>

function myFunction() {
    alert(convertTo24Hour("10:10pm"));
}
function convertTo24Hour(strtime) {
	var time = strtime.toLowerCase()
    var hours = parseInt(time.substr(0, 2));
    if(time.indexOf('am') != -1 && hours == 12) {
        time = time.replace('12', '0');
    }
    if(time.indexOf('pm')  != -1 && hours < 12) {
        time = time.replace(hours, (hours + 12));
    }
    return time.replace(/(am|pm)/, '');
}

</script>

</body>
</html>