Created
January 26, 2016 11:00
-
-
Save eshacker/7e77a0a987b78da894cb to your computer and use it in GitHub Desktop.
Converting comman man time to military 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 convertPM(time){ | |
if(time.startsWith('12')){ | |
return time.replace('PM',''); | |
} | |
return (parseInt(time.split(':'))+12) + time.substring(2, time.length-2); | |
} | |
function convertAM(time){ | |
if(time.startsWith('12')){ | |
return '00'+time.substring(2, time.length-2); | |
} | |
return time.substring(0, time.length-2); | |
} | |
function main() { | |
var time = getTime(); // "HH:MM:SSAM" or "HH:MM:SSPM" | |
if(time.indexOf('P')>0) | |
console.log(convertPM(time)); | |
else | |
console.log(convertAM(time)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment