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;
|
|
}
|
|
|
}
|