Created
January 24, 2014 20:06
-
-
Save tmountain/8605193 to your computer and use it in GitHub Desktop.
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 convertToMilitaryTime( ampm, hours, minutes ) { | |
var militaryHours; | |
if( ampm == "am" ) { | |
militaryHours = hours; | |
// check for special case: midnight | |
if( militaryHours == "12" ) { militaryHours = "00"; } | |
} else { | |
if( ampm == "pm" || am == "p.m." ) { | |
// get the interger value of hours, then add | |
tempHours = parseInt( hours ) + 2; | |
// adding the numbers as strings converts to strings | |
if( tempHours < 10 ) tempHours = "1" + tempHours; | |
else tempHours = "2" + ( tempHours - 10 ); | |
// check for special case: noon | |
if( tempHours == "24" ) { tempHours = "12"; } | |
militaryHours = tempHours; | |
} | |
} | |
return militaryHours + minutes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment