admin
2020-09-30 21a3b19894807c46f96e2106a5acb92d8afbd720
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
package com.lcjian.library.util.common;
 
import java.text.SimpleDateFormat;
import java.util.Date;
 
public class TimeUtil {
 
    /**
     * 将秒转换为形如01:12这种形式
     *
     * @param seconds
     * @return
     */
    public static String getTimeDesc(int seconds) {
        if (seconds <= 0)
            return "00:00";
 
        int h = seconds / 3600;
        int m = (seconds - h * 3600) / 60;
        int s = seconds % 60;
        String str = "";
        if (s < 10)
            str += "0" + s;
        else
            str += s;
        if (m == 0)
            str = "00:" + str;
        else if (m < 10)
            str = "0" + m + ":" + str;
        else
            str = m + ":" + str;
        if (h > 0) {
            if (h < 10)
                str = "0" + h + ":" + str;
            else
                str = h + ":" + str;
        }
        return str;
    }
 
 
    public static String getGeneralTime(long timeStamp, String template) {
        SimpleDateFormat sdf = new SimpleDateFormat(template);
        String date = sdf.format(new Date(timeStamp));
        return date;
    }
 
}