Class Stopwatch
java.lang.Object
Stopwatch
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintlap()laps the stopwatch
if the stopwatch is not running, this is equivalent to start()intread()reads the value of this stopwatchintread(int lap) reads the specific value of a lap on this stopwatch
lap numbers start from 0intread(int lap, boolean totalTime) reads the specific value of a lap on this stopwatch
lap numbers start from 0static Stringreadable(long milliseconds) converts the time in milliseconds to a human-readable stringvoidreset()resets the stopwatch
equivalent to writing (variable) = new Stopwatch();intstart()starts the stopwatchintstop()stops the stopwatch
can be restarted with "start()"
if stopwatch is not running, this is equivalent to reset()voidwait(int ms) waits for a set time
-
Constructor Details
-
Stopwatch
public Stopwatch()Constructs a Stopwatch
-
-
Method Details
-
start
public int start()starts the stopwatch- Returns:
- the time it took to start the stopwatch, typically very small
-
stop
public int stop()stops the stopwatch
can be restarted with "start()"
if stopwatch is not running, this is equivalent to reset()- Returns:
- equivalent to read()
-
lap
public int lap()laps the stopwatch
if the stopwatch is not running, this is equivalent to start()- Returns:
- equivalent to read()
-
read
public int read()reads the value of this stopwatch- Returns:
- value of this stopwatch
-
read
public int read(int lap) reads the specific value of a lap on this stopwatch
lap numbers start from 0- Parameters:
lap- the lap number- Returns:
- the length of this lap
equivalent to read(lap, false)
-
read
public int read(int lap, boolean totalTime) reads the specific value of a lap on this stopwatch
lap numbers start from 0- Parameters:
lap- the lap numbertotalTime- whether or not to count the total time since start()(true) or to count lap-to-lap(false)- Returns:
- the length of this lap
-
reset
public void reset()resets the stopwatch
equivalent to writing (variable) = new Stopwatch(); -
wait
public void wait(int ms) waits for a set time- Parameters:
ms- the time to wait in ms
-
readable
converts the time in milliseconds to a human-readable string- Parameters:
milliseconds- the number of milliseconds to convert- Returns:
- human-readable string
-