class StopWatch {
private long startTime;
private long endTime;
public void start() {
startTime = System.currentTimeMillis();
}
public void stop() {
endTime = System.currentTimeMillis();
}
public long getTime() {
return endTime - startTime;
}
@Override
public String toString() {
long timems = getTime();
long time = timems ⁄ 1000;
long hour = 0, minute = 0, second = 0;
second = time % 60L;
minute = time ⁄ 60L % 60L;
hour = time ⁄ 3600L;
return String.format("TimeMillis : %sms HH:MM:SS : %02d:%02d:%02d",
new Object[] {
Long.valueOf(timems),
Long.valueOf(hour),
Long.valueOf(minute),
Long.valueOf(second)
}
);
}
}