//获取当前时间
System.out.println(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss:SSS").format(new Date()));
/**
* 根据String型时间,获取long型时间,单位毫秒
* @param inVal 时间字符串
* @return long型时间
*/
public static long fromDateStringToLong(String inVal) {
Date date = null;
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss:SSS");
try {
date = inputFormat.parse(inVal);
} catch (Exception e) {
e.printStackTrace();
}
return date.getTime();
}
//获取当前时间为截止时间,转换为long型
long stopTime = fromDateStringToLong(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss:SSS").format(new Date()));
//获取当前时间为开始时间,转换为long型
long startTime =fromDateStringToLong(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss:SSS").format(new Date()));
//计算时间差,单位毫秒
long timeSpan = stopTime - startTime;