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 class
Time.Range
Represents a range of times.
-
Field Summary
Fields Modifier and Type Field Description int
hour
The hour value, in 24-hour format.int
millisecond
The millisecond value.static int
MILLISECONDS_PER_DAY
static int
MILLISECONDS_PER_HOUR
static int
MILLISECONDS_PER_MINUTE
static int
MILLISECONDS_PER_SECOND
int
minute
The minute value.static int
NANOS_PER_MILLI
int
second
The 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 aTime
from 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 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()
-
-
-
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 aTime
from 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:
compareTo
in interfacejava.lang.Comparable<Time>
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in 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 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.
-
-