Class Timer


  • public final class Timer
    extends Object
    Simple timer class.
    • Constructor Detail

      • Timer

        public Timer()
        Create a new timer. The new timer will NOT be started automatically. You need to invoke start() explicitly.
    • Method Detail

      • start

        public boolean start()
        (Re)start the timer. If the timer has already been started, does nothing.
        Returns:
        false iff the timer is already running.
      • stop

        public boolean stop()
        Stop the timer.
        Returns:
        false iff the timer is not running.
      • reset

        public boolean reset()
        Reset the timer to 0. The timer must be stopped before it can be reset.
        Returns:
        false iff the timer is currently running.
      • getTime

        public long getTime()
        Get the currently accumulated time. This method may be called while the timer is running, or after it has been stopped.
        Returns:
        The duration in milliseconds.
      • getTimeSpan

        public TimeSpan getTimeSpan()
        Get the accumulated time as a time span object.
        Returns:
        A time span object for the current value of the timer.
        See Also:
        getTime()