1 package jodd.datetime; 2 3 6 public class SimpleTimer { 7 8 private long startTime; 9 private long stopTime = 0; 10 11 12 15 public SimpleTimer() { 16 stopTime = 0; 17 start(); 18 } 19 20 23 public void start() { 24 startTime = System.currentTimeMillis(); 25 } 26 27 32 public long stop() { 33 stopTime = System.currentTimeMillis(); 34 return stopTime - startTime; 35 } 36 37 42 public long lap() { 43 return System.currentTimeMillis() - startTime; 44 } 45 46 52 public long elapsed() { 53 if (stopTime < startTime) { 54 stopTime = System.currentTimeMillis(); 55 } 56 return stopTime - startTime; 57 } 58 59 60 65 public String toString() { 66 return (new Long(stopTime - startTime)).toString(); 67 } 68 } 69 | Popular Tags |