Convert from 12-hour to 24-hour time. #hackerrank #warmup
/*
Solution for HackerRank > Algorithms > Warmup > Time Conversion
https://www.hackerrank.com/challenges/time-conversion
*/
function main() {
var time = '12:54:54PM';
var period = time.slice(-2);
var hour = time.slice(0,2);
var military;
if ( period == 'PM' && eval(hour) != '12') {
var conversion = eval(hour) + 12;
time = time.replace(hour, conversion);
} else if ( period == 'AM' && eval(hour) == '12') {
time = time.replace(hour,'00');
}
military = time.slice(0,-2);
console.log(military);
}
main();