Class Timer


  • public class Timer
    extends Object
    Duration timer for elapsed wall-clock time. A Timer provides stop-watch like behavior useful for timing the duration between events.
    • Constructor Detail

      • Timer

        public Timer()
        Create a new timer. The timer reads no time elapsed and is inactive.
    • Method Detail

      • start

        public void start()
        Starts the timer. The timer is considered active and measures the time elapsed since calling start().
      • getStartTime

        public long getStartTime()
        Gets the time at which the timer was last started.
        Returns:
        the start time, as milliseconds since epoch
      • getDuration

        public long getDuration()
        Gets the accumulated time elapsed, in milliseconds. If the timer is active, this is the time elapsed since calling start(). If it is inactive, this is the amount of time which passed between the start() and stop() calls.
        Returns:
        the total elapsed time, in milliseconds
      • getEndTime

        public long getEndTime()
        Gets the time at which the timer was stopped.
        Returns:
        the end time, as milliseconds since epoch. If the timer is still active then Long.MIN_VALUE.
      • stop

        public void stop()
        Stops the timer. If active, the timer becomes inactive and ceases to accumulate elapsed time. Until restarted, the reported duration is the interval of time between the call to stop() and the previous call to start().