Class Duration


  • public final class Duration
    extends java.lang.Object
    This class lets its users define an interval of time which can be defined in terms of days, hours, minutes, seconds and milliseconds.

    It has various constructors to let the user easily define an interval of time.

    • Constructor Summary

      Constructors 
      Constructor Description
      Duration​(long duration)
      The duration is defined by milliseconds.
      Duration​(long days, int hours, int minutes, int seconds, int milliseconds)
      The interval is set by setting all the possible values.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      long getDays()
      Gets the days part of the duration.
      int getHours()
      Gets the hours part of the duration.
      int getMilliseconds()
      Gets the milliseconds part of the duration.
      int getMinutes()
      Gets the minutes part of the duration.
      int getSeconds()
      Gets the seconds part of the duration.
      long getTotalMilliseconds()
      Gets the total milliseconds of the duration.
      int hashCode()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Duration

        public Duration​(long days,
                        int hours,
                        int minutes,
                        int seconds,
                        int milliseconds)
        The interval is set by setting all the possible values.
        Parameters:
        days - Day(s).
        hours - Hour(s) in range [-23, 23].
        minutes - Minute(s) in range [-59, 59].
        seconds - Second(s) in range [-59, 59].
        milliseconds - Milliseconds in range [0, 999].
      • Duration

        public Duration​(long duration)
        The duration is defined by milliseconds. The class will calculate the number of days, hours, minutes, seconds and milliseconds from that value.
        Parameters:
        duration - The duration in milliseconds.
    • Method Detail

      • getDays

        public long getDays()
        Gets the days part of the duration.
      • getHours

        public int getHours()
        Gets the hours part of the duration.
      • getMinutes

        public int getMinutes()
        Gets the minutes part of the duration.
      • getSeconds

        public int getSeconds()
        Gets the seconds part of the duration.
      • getMilliseconds

        public int getMilliseconds()
        Gets the milliseconds part of the duration.
      • getTotalMilliseconds

        public long getTotalMilliseconds()
        Gets the total milliseconds of the duration.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object