zsh_root
2025-01-06 7857a444de69124e9f7fb45f98b0ae818b107f23
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
package tools;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
 
public class GetNowTime {
 
    public static String now() {//获取时间方法
        String msg="";
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
        msg+="["+sdf.format(date)+"]";
        return msg;
 
    }
 
    /**获取年月日时分秒毫秒时间 2020-05-30 12:33:45.23*/
    public static String timestamp2() {
        String d=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(Calendar.getInstance().getTime());
        d="["+d+"]";
        return d;
    }
 
 
    public static int timestamp() {
 
        int time=0;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
        String inputString =sss();
        Date date = null;
        try {
            date = sdf.parse("1970-01-01 " + inputString);
        } catch (ParseException e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
 
        time=(int) date.getTime();
        return time;
    }
 
    /**获取毫秒时间戳21:49:27.519*/
    public static String sss() {//获取时间方法
        String msg="";
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
        msg+=sdf.format(date);
        return msg;
 
    }
 
 
}