Package org.apache.pivot.util
Class Time
- java.lang.Object
-
- org.apache.pivot.util.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 classTime.RangeRepresents a range of times.
-
Field Summary
Fields Modifier and Type Field Description inthourThe hour value, in 24-hour format.intmillisecondThe millisecond value.static intMILLISECONDS_PER_DAYstatic intMILLISECONDS_PER_HOURstatic intMILLISECONDS_PER_MINUTEstatic intMILLISECONDS_PER_SECONDintminuteThe minute value.static intNANOS_PER_MILLIintsecondThe second value.
-
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 aTimefrom aLocalTime, 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 Timeadd(int milliseconds)Adds the specified milliseconds of days to this time and returns the resulting time.intcompareTo(Time time)static Timedecode(java.lang.String value)Creates a new time representing the specified time string.booleanequals(java.lang.Object o)inthashCode()intsubtract(Time time)Gets the number of milliseconds in between this time and the specified time.java.time.LocalTimetoLocalTime()inttoMilliseconds()java.lang.StringtoString()
-
-
-
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
-
MILLISECONDS_PER_HOUR
public static final int MILLISECONDS_PER_HOUR
- See Also:
- Constant Field Values
-
MILLISECONDS_PER_DAY
public static final int MILLISECONDS_PER_DAY
- See Also:
- Constant Field Values
-
NANOS_PER_MILLI
public static final int NANOS_PER_MILLI
- 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 aTimefrom aLocalTime, 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:
compareToin interfacejava.lang.Comparable<Time>
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.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 fullISO 8601extended "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
Timevalue corresponding to the input string.
-
-