Military to Standard Time

Convert time formats instantly. This script takes a 24-hour integer or string and transforms it into the AM/PM format used in daily life.

Copy the Script

<script>
function toStandardTime(timeStr) {
    // Expects "HH:MM" string
    var timeSplit = timeStr.split(':');
    var hours = Number(timeSplit[0]);
    var minutes = Number(timeSplit[1]);
    var meridian = "";

    if (hours > 12) {
        meridian = "PM";
        hours -= 12;
    } else if (hours < 12) {
        meridian = "AM";
        if (hours == 0) hours = 12;
    } else {
        meridian = "PM"; // 12 noon
    }
    
    return hours + ":" + (minutes < 10 ? "0"+minutes : minutes) + " " + meridian;
}
// alert(toStandardTime("14:30")); // Outputs 2:30 PM
</script>

Frequently Asked Questions

Military time is a 24-hour clock system used to avoid confusion between AM and PM (e.g., 13:00 is 1:00 PM).

Yes. 00:00 or 24:00 is converted to 12:00 AM.

Yes. You can attach this function to an `onchange` event of an input field to automatically format user entries.