Created
November 11, 2019 08:36
-
-
Save MuhiaKevin/a26ead243793ca12a96a08225e9ba9c3 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 timeConversion(stringg){ | |
let hour = stringg.substring(0,2) | |
let mins = stringg.substring(3,5) | |
let seconds = stringg.substring(6,8) | |
let timeconvention = stringg.substring(8,10) | |
let rest = stringg.substring(2,8) | |
if(timeconvention == 'PM'){ | |
if(parseInt(hour) != 12){ | |
let hour1 = 0 | |
hour1 = parseInt(hour) + 12 | |
console.log(hour1.toString() + rest) | |
return hour1.toString() + rest | |
} | |
else{ | |
console.log(hour + rest) | |
return hour + rest | |
} | |
} | |
else if(timeconvention == 'AM'){ | |
if(parseInt(hour) != 12){ | |
console.log(hour + rest) | |
return hour + rest | |
} | |
else{ | |
console.log('00'+rest) | |
return '00'+rest | |
} | |
} | |
} | |
timeConversion('12:05:45AM') | |
timeConversion('02:05:30PM') | |
timeConversion('08:05:25AM') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment