TimeUtils.java
1.45 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package ipipan.clarin.tei.impl.utils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
/**
*
* @author mlenart
*/
public class TimeUtils {
private final static SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd");
private final static SimpleDateFormat timeFormat = new SimpleDateFormat(
"HH:mm:ss");
public static String getTimeStr(Calendar cal) {
return timeFormat.format(cal.getTime());
// return String.format(
// "%s:%s:%s",
// getStr(cal.get(Calendar.HOUR_OF_DAY)),
// getStr(cal.get(Calendar.MINUTE)),
// getStr(cal.get(Calendar.SECOND)));
}
public static String getDateStr(Calendar cal) {
return dateFormat.format(cal.getTime());
// logger.debug(cal);
// String res = String.format(
// "%s-%s-%s",
// getStr(cal.get(Calendar.YEAR)),
// getStr(cal.get(Calendar.MONTH)),
// getStr(cal.get(Calendar.DAY_OF_MONTH)));
// logger.debug(res);
// return res;
}
public static String getW3CTime(long time) {
return String.format("PT%sH%sM%sS", getHours(time), getMinutes(time),
getSeconds(time));
}
private static String getStr(long t) {
return t < 10 ? "0" + t : "" + t;
}
private static String getHours(long time) {
long h = time / 1000 / 3600;
return getStr(h);
}
private static String getMinutes(long time) {
long m = (time / 1000 / 60) % 60;
return getStr(m);
}
private static String getSeconds(long time) {
return "" + (time / 1000 % 60) + "." + getStr((time % 1000 / 10));
}
}