-
Notifications
You must be signed in to change notification settings - Fork 0
/
sollersTest.java
37 lines (28 loc) · 1.14 KB
/
sollersTest.java
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
import java.util.*;
import java.io.*;
import java.time.*;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
public class sollersTest {
public static String StringChallenge(String str) {
String [] parts = str.split("-");
String start = parts[0];
String end = parts[1];
DateTimeFormatter formatter =DateTimeFormatter.ofPattern("hh:mm a");
LocalTime starttime = LocalTime.parse(formatS(start),formatter);
LocalTime endtime = LocalTime.parse(formatS(end),formatter);
Duration duration = Duration.between(starttime,endtime);
return String.valueOf(Math.abs(duration.toMinutes()));
}
public static String formatS(String date){
String a = date.substring(date.length()-2).toUpperCase();
String str = date.substring(0,date.length()-2).concat(" ").concat(a);
return str;
}
//12:30pm-12:00am
public static void main (String[] args) {
// keep this function call here
Scanner s = new Scanner(System.in);
System.out.print(StringChallenge(s.nextLine()));
}
}