-
-
Notifications
You must be signed in to change notification settings - Fork 337
Expand file tree
/
Copy path4.js
More file actions
42 lines (28 loc) · 1.02 KB
/
4.js
File metadata and controls
42 lines (28 loc) · 1.02 KB
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
34
35
36
37
38
39
40
41
42
//const twelveHourClockTime = "20:53";
//const twentyFourHourClockTime = "08:53";
//variable names can't start with a number
// the times are in the wrong places ie:-20:53 is not a twelve hour time and as they are const they cant be directly changed
let twelveHourClockTime = "13.00";
let twelthHour = twelveHourClockTime.substring(
0,
twelveHourClockTime.length - 3
);
let sufix =".AM"
if (twelthHour => 13) {
twelthHour = twelthHour - 12;
sufix =".PM"
}
let twelthMinutes = twelveHourClockTime.substring(
2,
twelveHourClockTime.length
);
let twentyFourHourClockTime = "08:53.pm";
let twentyFour = twentyFourHourClockTime.substring(0,
twentyFourHourClockTime.length -6)
twentyFour = parseInt(twentyFour);
if (twentyFourHourClockTime.match (/(pm|PM)/g)){
twentyFour = twentyFour + 12;
}
let twentyFourMinuies = twentyFourHourClockTime.substring(2, twentyFourHourClockTime.length -3);
console.log(`${twelthHour}${twelthMinutes}${sufix}`);
console.log(`${twentyFour}${twentyFourMinuies}`);