获取某个输入时间时间戳:
System.out.println("请输入启动时间(格式为yyyy-MM-dd HH:mm:ss):");
String startTime = sc.nextLine();
System.out.println("你输入的启动时间为:"+startTime);
//String startTime="2015-03-05 12:00:00";
SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date= null;
try {
date = simpleDateFormat.parse(startTime);
} catch (ParseException e) {
e.printStackTrace();
}
long timeStemp = date.getTime();
获取当前时间时间戳:
1. new Date().getTime();
2. System.currentTimeMillis();
2比1稍快;