Class Time

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<Time>

    public final class Time
    extends java.lang.Object
    implements java.lang.Comparable<Time>, java.io.Serializable
    Class representing a time of day, independent of any particular time zone.
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Time.Range
      Represents a range of times.
    • Constructor Summary

      Constructors 
      Constructor Description
      Time()  
      Time​(int milliseconds)  
      Time​(int hour, int minute, int second)  
      Time​(int hour, int minute, int second, int millisecond)  
      Time​(java.time.LocalTime localTime)
      Construct a Time from a LocalTime, rounding up the nanosecond value to our milliseconds.
      Time​(java.util.Calendar calendar)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Time add​(int milliseconds)
      Adds the specified milliseconds of days to this time and returns the resulting time.
      int compareTo​(Time time)  
      static Time decode​(java.lang.String value)
      Creates a new time representing the specified time string.
      boolean equals​(java.lang.Object o)  
      int hashCode()  
      int subtract​(Time time)
      Gets the number of milliseconds in between this time and the specified time.
      java.time.LocalTime toLocalTime()  
      int toMilliseconds()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • hour

        public final int hour
        The hour value, in 24-hour format.
      • minute

        public final int minute
        The minute value.
      • second

        public final int second
        The second value.
      • millisecond

        public final int millisecond
        The millisecond value.
      • MILLISECONDS_PER_SECOND

        public static final int MILLISECONDS_PER_SECOND
        See Also:
        Constant Field Values
      • MILLISECONDS_PER_MINUTE

        public static final int MILLISECONDS_PER_MINUTE
        See Also:
        Constant Field Values
    • Constructor Detail

      • Time

        public Time()
      • Time

        public Time​(java.util.Calendar calendar)
      • Time

        public Time​(int hour,
                    int minute,
                    int second)
      • Time

        public Time​(int hour,
                    int minute,
                    int second,
                    int millisecond)
      • Time

        public Time​(int milliseconds)
      • Time

        public Time​(java.time.LocalTime localTime)
        Construct a Time from a LocalTime, rounding up the nanosecond value to our milliseconds.
        Parameters:
        localTime - The local time to convert.
        See Also:
        NANOS_PER_MILLI
    • Method Detail

      • add

        public Time add​(int milliseconds)
        Adds the specified milliseconds of days to this time and returns the resulting time. The number of milliseconds may be negative, in which case the result will be a time prior to this time.
        Parameters:
        milliseconds - The number of milliseconds to add to this time.
        Returns:
        The resulting time.
      • subtract

        public int subtract​(Time time)
        Gets the number of milliseconds in between this time and the specified time. If this time represents a time later than the specified time, the difference will be positive. If this time represents a time before the specified time, the difference will be negative. If the two times represent the same time, the difference will be zero.
        Parameters:
        time - The time to subtract from this time.
        Returns:
        The number of milliseconds in between this time and time.
      • toMilliseconds

        public int toMilliseconds()
        Returns:
        The number of milliseconds since midnight represented by this time.
      • toLocalTime

        public java.time.LocalTime toLocalTime()
        Returns:
        This time converted to a LocalTime.
      • compareTo

        public int compareTo​(Time time)
        Specified by:
        compareTo in interface java.lang.Comparable<Time>
      • equals

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

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

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

        public static Time decode​(java.lang.String value)
        Creates a new time representing the specified time string. The time string must be in the full ISO 8601 extended "time" format, which is [hh]:[mm]:[ss]. An optional millisecond suffix of the form .[nnn] is also supported.
        Parameters:
        value - A string in the form of [hh]:[mm]:[ss] or [hh]:[mm]:[ss].[nnn] (e.g. 17:19:20 or 17:19:20.412).
        Returns:
        The Time value corresponding to the input string.