Class TimeSpan

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DAYS
      Constant for days unit and conversion.
      static int HOURS
      Constant for hours unit and conversion.
      static TimeSpan MAX_VALUE
      Represents the Maximum TimeSpan value.
      static int MILLISECONDS
      Constant for milliseconds unit and conversion.
      static TimeSpan MIN_VALUE
      Represents the Minimum TimeSpan value.
      static int MINUTES
      Constant for minutes unit and conversion.
      static int SECONDS
      Constant for seconds unit and conversion.
      static TimeSpan ZERO
      Represents the TimeSpan with a value of zero.
    • Constructor Summary

      Constructors 
      Constructor Description
      TimeSpan​(int units, long value)
      Creates a new TimeSpan object based on the unit and value entered.
      TimeSpan​(long time)
      Creates a new instance of TimeSpan based on the number of milliseconds entered.
    • Constructor Detail

      • TimeSpan

        public TimeSpan​(long time)
        Creates a new instance of TimeSpan based on the number of milliseconds entered.
        Parameters:
        time - the number of milliseconds for this TimeSpan.
      • TimeSpan

        public TimeSpan​(int units,
                        long value)
        Creates a new TimeSpan object based on the unit and value entered.
        Parameters:
        units - the type of unit to use to create a TimeSpan instance.
        value - the number of units to use to create a TimeSpan instance.
    • Method Detail

      • subtract

        public static TimeSpan subtract​(Date date1,
                                        Date date2)
        Subtracts two Date objects creating a new TimeSpan object.
        Parameters:
        date1 - Date to use as the base value.
        date2 - Date to subtract from the base value.
        Returns:
        a TimeSpan object representing the difference bewteen the two Date objects.
      • compareTo

        public int compareTo​(TimeSpan o)
        Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object. Comparison is based on the number of milliseconds in this TimeSpan.
        Specified by:
        compareTo in interface Comparable<TimeSpan>
        Parameters:
        o - the Object to be compared.
        Returns:
        a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
      • equals

        public boolean equals​(Object obj)
        Indicates whether some other object is "equal to" this one. Comparison is based on the number of milliseconds in this TimeSpan.
        Overrides:
        equals in class Object
        Parameters:
        obj - the reference object with which to compare.
        Returns:
        if the obj argument is a TimeSpan object with the exact same number of milliseconds. otherwise.
      • hashCode

        public int hashCode()
        Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable. The method uses the same algorithm as found in the Long class.
        Overrides:
        hashCode in class Object
        Returns:
        a hash code value for this object.
        See Also:
        Object.equals(Object), Hashtable
      • toString

        public String toString()
        Returns a string representation of the object in the format. "[-]d.hh:mm:ss.ff" where "-" is an optional sign for negative TimeSpan values, the "d" component is days, "hh" is hours, "mm" is minutes, "ss" is seconds, and "ff" is milliseconds
        Overrides:
        toString in class Object
        Returns:
        a string containing the number of milliseconds.
      • clone

        public Object clone()
        Returns a clone of this TimeSpan.
        Overrides:
        clone in class Object
        Returns:
        a clone of this TimeSpan.
      • isPositive

        public boolean isPositive()
        Indicates whether the value of the TimeSpan is positive.
        Returns:
        if the value of the TimeSpan is greater than zero. otherwise.
      • isNegative

        public boolean isNegative()
        Indicates whether the value of the TimeSpan is negative.
        Returns:
        if the value of the TimeSpan is less than zero. otherwise.
      • isZero

        public boolean isZero()
        Indicates whether the value of the TimeSpan is zero.
        Returns:
        if the value of the TimeSpan is equal to zero. otherwise.
      • getMilliseconds

        public long getMilliseconds()
        Gets the number of milliseconds.
        Returns:
        the number of milliseconds.
      • getTotalMilliseconds

        public long getTotalMilliseconds()
        Gets the number of milliseconds.
        Returns:
        the number of milliseconds.
      • getSeconds

        public long getSeconds()
        Gets the number of seconds (truncated).
        Returns:
        the number of seconds.
      • getTotalSeconds

        public double getTotalSeconds()
        Gets the number of seconds including fractional seconds.
        Returns:
        the number of seconds.
      • getMinutes

        public long getMinutes()
        Gets the number of minutes (truncated).
        Returns:
        the number of minutes.
      • getTotalMinutes

        public double getTotalMinutes()
        Gets the number of minutes including fractional minutes.
        Returns:
        the number of minutes.
      • getHours

        public long getHours()
        Gets the number of hours (truncated).
        Returns:
        the number of hours.
      • getTotalHours

        public double getTotalHours()
        Gets the number of hours including fractional hours.
        Returns:
        the number of hours.
      • getDays

        public long getDays()
        Gets the number of days (truncated).
        Returns:
        the number of days.
      • getTotalDays

        public double getTotalDays()
        Gets the number of days including fractional days.
        Returns:
        the number of days.
      • add

        public void add​(TimeSpan timespan)
        Adds a TimeSpan to this TimeSpan.
        Parameters:
        timespan - the TimeSpan to add to this TimeSpan.
      • add

        public void add​(int units,
                        long value)
        Adds a number of units to this TimeSpan.
        Parameters:
        units - the type of unit to add to this TimeSpan.
        value - the number of units to add to this TimeSpan.
      • compare

        public static int compare​(TimeSpan first,
                                  TimeSpan second)
        Compares two TimeSpan objects.
        Parameters:
        first - first TimeSpan to use in the compare.
        second - second TimeSpan to use in the compare.
        Returns:
        a negative integer, zero, or a positive integer as the first TimeSpan is less than, equal to, or greater than the second TimeSpan.
      • duration

        public TimeSpan duration()
        Returns a TimeSpan whose value is the absolute value of this TimeSpan.
        Returns:
        a TimeSpan whose value is the absolute value of this TimeSpan.
      • negate

        public TimeSpan negate()
        Returns a TimeSpan whose value is the negated value of this TimeSpan.
        Returns:
        a TimeSpan whose value is the negated value of this TimeSpan.
      • subtract

        public void subtract​(TimeSpan timespan)
        Subtracts a TimeSpan from this TimeSpan.
        Parameters:
        timespan - the TimeSpan to subtract from this TimeSpan.
      • subtract

        public void subtract​(int units,
                             long value)
        Subtracts a number of units from this TimeSpan.
        Parameters:
        units - the type of unit to subtract from this TimeSpan.
        value - the number of units to subtract from this TimeSpan.