-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleDate.java
More file actions
30 lines (25 loc) · 843 Bytes
/
SimpleDate.java
File metadata and controls
30 lines (25 loc) · 843 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
30
import java.util.ArrayList;
public class SimpleDate {
public static void main(String[] args) throws Exception {
ArrayList<String> timestampsList = new ArrayList<String>();
timestampsList.add("01/00/05");
timestampsList.add("10/00/05");
long tm = 0;
for (String tmp : timestampsList){
String[] arr = tmp.split("/");
tm += Integer.parseInt(arr[2]);
tm += 60 * Integer.parseInt(arr[1]);
tm += 3600 * Integer.parseInt(arr[0]);
}
long hh = tm / 3600;
tm %= 3600;
long mm = tm / 60;
tm %= 60;
long ss = tm;
System.out.println(format(hh) + "/" + format(mm) + "/" + format(ss));
}
private static String format(long s){
if (s < 10) return "0" + s;
else return "" + s;
}
}