我尝试了以下代码,但仍然得到了相同的结果:
代码1
long start=System.currentTimeMillis();
try {
Thread.sleep(3000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
long finish=System.currentTimeMillis();
Date date1 = new Date(finish- start);
DateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS");
String dateFormatted = formatter.format(date1);
System.out.println(dateFormatted);
代码2
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(appTerminateTime - appStartTime);
return "session lasted for " + calendar.get(Calendar.HOUR) + ":" + calendar.get(Calendar.MINUTE) + ":" + calendar.get(Calendar.SECOND);