-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12-5.js
More file actions
29 lines (26 loc) · 732 Bytes
/
Copy path12-5.js
File metadata and controls
29 lines (26 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function toMilitary (time) {
if (time.substr(0,2) == "12" && time.substr(time.length -2) == "am" ){
first = time.slice(2)
hours = "00" + first
hours = hours.substr(0,time.length -2)
return hours
}
else if (time.substr(0,2) == "12" && time.substr(time.length -2) == "pm" ){
hours = time.substr(0,time.length -2)
return hours
}
else if (time.substr(time.length -2) == "am"){
hours = time.substr(0,time.length -2)
if (hours.length == 4) hours = "0" + hours
return hours
}
else if (time.substr(time.length -2) == "pm"){
hours = time.split(":")
h = parseInt(hours[0]) + 12 + ":" + hours[1]
h = h.substr(0,h.length -2)
return h
}
else{
return time
}
}