Skip to content

Instantly share code, notes, and snippets.

@kavitshah8
Last active October 26, 2016 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kavitshah8/3d886622869d71fa49afe107f5c18a6b to your computer and use it in GitHub Desktop.
Save kavitshah8/3d886622869d71fa49afe107f5c18a6b to your computer and use it in GitHub Desktop.
Hacker
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