-
Notifications
You must be signed in to change notification settings - Fork 3
/
Time_Format.java
47 lines (40 loc) · 1.64 KB
/
Time_Format.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
38
39
40
41
42
43
44
45
46
47
package demon;
import java.time.*;
import java.util.Arrays;
public class Time_Format {
public static void main(String[] args) {
// TODO Auto-generated method stub
String test = "2019-10-19T00:55:31";
String hour = test.substring(11,13);
String min = test.substring(14,16);
String[] time = new String[2];
time = getTime(hour, min);
System.out.println(Arrays.toString(time));
}
private static String[] getTime(String arrival_hour, String arrival_min) {
String[] s = new String[2];
LocalTime tm = java.time.LocalTime.now();
int hr = Integer.parseInt(arrival_hour);
int min = Integer.parseInt(arrival_min);
if(hr == 0) {
s[0] = String.format("Arival Time: %d:%s AM", (Integer.parseInt(arrival_hour)+12), arrival_min);
s[1] = String.format("Time Left: %d", (Integer.parseInt(arrival_min)- tm.getMinute()));
}
else if(hr == 12) {
s[0] = String.format("Arival Time: %d:%s PM", (Integer.parseInt(arrival_hour)-12), arrival_min);
s[1] = String.format("Time Left: %s", arrival_min);
}
else if(hr > 12 && hr < 0) {
int hr_remaining = java.lang.Math.abs(tm.getHour()- hr);
int min_remaining = java.lang.Math.abs(tm.getMinute()-min);
s[0] = String.format("Arival Time: %s:%s PM", (Integer.parseInt(arrival_hour)-12), arrival_min);
s[1] = String.format("Time Left: %d min" , min_remaining);
}
else {//hr > 24 && hr < 12
int min_remaining = java.lang.Math.abs(tm.getMinute()-min);
s[0] = String.format("Arival Time: %s:%s AM", (Integer.parseInt(arrival_hour)-12), arrival_min);
s[1] = String.format("Time Left: %d min" , min_remaining);
}
return s;
}
}