public long getTime ( ) throws NotAvailableException { synchronized ( timeSync ) { try { if ( ! isRunning ( ) ) { throw new InvalidStateException ( "Stopwatch was never started!" ) ; } if ( endTime == - 1 ) { return System . currentTimeMillis ( ) - startTime ; } return endTime - startTime ; } catch ( CouldNotPerformException ex ) { throw new NotAvailableException ( ContextType . INSTANCE , "time" , ex ) ; } } }
This method returns the time interval between the start - and end timestamps . In case the the Stopwatch is still running the elapsed time since Stopwatch start will be returned .