Class TimeDuration


  • public class TimeDuration
    extends Object
    This class specifies a duration with a precision of milliseconds. It consists of a number and a time unit. For example: 30 minutes or 2 hours.
    • Constructor Detail

      • TimeDuration

        public TimeDuration​(int count,
                            TimeUnit unit)
        Constructs a new time duration.
        Parameters:
        count - the number of time units
        unit - the time unit
    • Method Detail

      • getCount

        public int getCount()
        Returns the number of time units that defines this duration. The time unit is obtained with getUnit().
        Returns:
        the number of time units
      • getUnit

        public TimeUnit getUnit()
        Returns the time unit that, together with the number returned by getCount(), defines this duration.
        Returns:
        the time unit
      • getDuration

        public long getDuration()
        Returns the duration in milliseconds.
        Returns:
        the duration in milliseconds
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • parse

        public static TimeDuration parse​(String s,
                                         TimeUnit min,
                                         TimeUnit max)
                                  throws ParseException
        Parses a time duration from a string. The string should consist of a number and a time unit, separated by white space. You can specify the smallest and largest allowed time unit.
        Parameters:
        s - the string
        min - the smallest allowed time unit. You can set this to null for the smallest known time unit.
        max - the largest allowed time unit. You can set this to null for the largest known time unit.
        Returns:
        the time duration
        Throws:
        ParseException - if the string is invalid