DateUtil.java
1.05 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
package com.chudiangameplay.android.util;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
/**
* Created by Administrator on 2018/8/15.
* 时间工具类
*/
public class DateUtil {
/**
* 时间戳转日期
*
* @param timeLong 给定的时间戳
* @return 当前日期
*/
public static String getDateFromTimeLine(long timeLong) {
if (timeLong == 0) {
return "";
}
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return format.format(new Date(timeLong));
}
public static String formatHours(long timeLong) {
if (timeLong == 0) {
return "";
}
long hour = timeLong / 1000 / 3600;
SimpleDateFormat format;
if (hour > 0) {
format = new SimpleDateFormat("HH:mm:ss");
} else {
format = new SimpleDateFormat("mm:ss");
}
format.setTimeZone(TimeZone.getTimeZone("GMT+00:00"));
return format.format(new Date(timeLong));
}
}