org.apache.pivot.util
Class Time

java.lang.Object
  extended by org.apache.pivot.util.Time
All Implemented Interfaces:
Serializable, Comparable<Time>

public final class Time
extends Object
implements Comparable<Time>, Serializable

Class representing a time of day, independent of any particular time zone.

See Also:
Serialized Form

Nested Class Summary
static class Time.Range
          Represents a range of times.
 
Field Summary
 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.
 int second
          The second value.
 
Constructor Summary
Time()
           
Time(Calendar calendar)
           
Time(int milliseconds)
           
Time(int hour, int minute, int second)
           
Time(int hour, int minute, int second, int millisecond)
           
 
Method Summary
 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(String value)
          Creates a new time representing the specified time string.
 boolean equals(Object o)
           
 int hashCode()
           
 int subtract(Time time)
          Gets the number of milliseconds in between this time and the specified time.
 int toMilliseconds()
          Returns the number of milliseconds since midnight represented by this time.
 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

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
Constructor Detail

Time

public Time()

Time

public Time(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)
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.

Returns:
The number of milliseconds since midnight represented by this time.

compareTo

public int compareTo(Time time)
Specified by:
compareTo in interface Comparable<Time>

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

decode

public static Time decode(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).