1function convertTime12To24(time) {
2 var hours = Number(time.match(/^(\d+)/)[1]);
3 var minutes = Number(time.match(/:(\d+)/)[1]);
4 var AMPM = time.match(/\s(.*)$/)[1];
5 if (AMPM === "PM" && hours < 12) hours = hours + 12;
6 if (AMPM === "AM" && hours === 12) hours = hours - 12;
7 var sHours = hours.toString();
8 var sMinutes = minutes.toString();
9 if (hours < 10) sHours = "0" + sHours;
10 if (minutes < 10) sMinutes = "0" + sMinutes;
11 return (sHours + ":" + sMinutes);
12}