package test;
import java.util.Date;
/**
* *
* Simple timer. call start(), do stuff, call stop() or timer.toString();
*
* Not thread safe.
*
* @author jbrown
*/
public final class TimeCommand {
private long start = 0;
private long end = 0;
/**
* start the clock
*/
public void start() {
Date now = new Date();
start = now.getTime();
end = 0;
}
/**
* stop the clock
*
* @return number of milliseconds between start and stop
*/
public long stop() {
Date now = new Date();
end = now.getTime();
return (end - start);
}
/**
* Retrieve milliseconds
*
* @return number of milliseconds between start and stop
*/
public long getMilliseconds() {
if (end == 0) {
stop();
}
return (end - start);
}
// diff time as string
@Override
public String toString() {
return "Time[" + getMilliseconds() + " ms]";
}
}