1
zhanghua
2024-09-26 c775c6953d9759e70f08acbfa8f6d7490aaae3d1
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
package com.netsdk.demo.units;
 
import java.text.SimpleDateFormat;
import java.util.Date;
 
/**
 * @description:
 * @author: 251589
 * @time: 2020/11/17 16:34
 */
public class TimeUtils {
 
    // 获取 年-月-日 时:分:秒格式的时间字符串 入参 long
    public static String getTimeStr(long timestamp) {
        String format = "yyyy-MM-dd HH:mm:ss";
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(new Date(timestamp));
    }
 
    // 获取 年-月-日 时:分:秒格式的时间字符串 入参 Date
    public static String getTimeStr(Date date) {
        String format = "yyyy-MM-dd HH:mm:ss";
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }
 
 
    // 获取 年月日时分秒格式的时间字符串 入参 long
    public static String getTimeStringWithoutSign(long timestamp) {
        String format = "yyyMMddHHmmss";
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(new Date(timestamp));
    }
 
    // 获取 年月日时分秒格式的时间字符串 入参 Date
    public static String getTimeStringWithoutSign(Date date) {
        String format = "yyyMMddHHmmss";
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }
 
    private TimeUtils() {
    }
 
 
}