Created
December 25, 2022 05:30
-
-
Save thmain/1839e67f348093e3bf14fa140c1587f4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 timeConvertor(time) { | |
var PM = time.match('PM') ? true : false | |
time = time.split(':') | |
var min = time[1] | |
if (PM) { | |
var hour = 12 + parseInt(time[0],10) | |
var sec = time[2].replace('PM', '') | |
} else { | |
var hour = time[0] | |
var sec = time[2].replace('AM', '') | |
} | |
console.log(hour + ':' + min + ':' + sec) | |
} | |
timeConvertor('07:03:15PM'); // "19:03:15" | |
timeConvertor('1:53:55AM'); // "1:53:55" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment