Skip to content

Instantly share code, notes, and snippets.

@tbennett
Created December 12, 2023 01:09
Show Gist options
  • Save tbennett/416f91cb94933cbe759c4e2cce5431b1 to your computer and use it in GitHub Desktop.
Save tbennett/416f91cb94933cbe759c4e2cce5431b1 to your computer and use it in GitHub Desktop.
Convert 24hr (Militarty) time to standard 12hr time
function convertMilitaryToStandard(militaryTime) {
let hours = militaryTime.substring(0,2);
let minutes = militaryTime.substring(3,5);
let meridian = (hours >= 12) ? "PM" : "AM";
let convertedTime = ((parseInt(hours) + 11) % 12 + 1) + ":" + minutes;
return convertedTime + " " + meridian;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment