Created
December 12, 2023 01:09
-
-
Save tbennett/416f91cb94933cbe759c4e2cce5431b1 to your computer and use it in GitHub Desktop.
Convert 24hr (Militarty) time to standard 12hr time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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