-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHK9.js
33 lines (32 loc) · 910 Bytes
/
HK9.js
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
30
31
32
33
function timeConversion(s) {
let parts = s.split(':')
let lastPart = parts[2].split('')
let condition = lastPart[2]+lastPart[3]
let transformedString = ''
if (condition == 'PM') {
if (parts[0] !== 12) {
let newHourPm = parts[0]*1 +12
transformedString += newHourPm
+':'
+ parts[1]
+ ':'
+ lastPart[0]+lastPart[1]
}else{
transformedString += s-condition
}
}else if (condition == 'AM') {
if (parts[0] == 12) {
let newHourAm = parts[0]*1 -12
transformedString += newHourAm
+'0:'
+ parts[1]
+':'
+ lastPart[0]+lastPart[1]
}else{
transformedString += s-condition
}
}
return transformedString
}
console.log(timeConversion('07:05:45PM'));
//must return '19:05:45'