public final class Time extends java.lang.Object implements java.lang.Comparable<Time>, java.io.Serializable
Instances of this class are immutable. You can safely reuse them and call them from multiple threads at once.
| Constructor and Description |
|---|
Time(int hour,
int minute)
Constructs a
Time object representing a time with the
specified hour and minute. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
after(Time comparisonTime)
Returns
true if this Time is chronologically
after comparisonTime (assuming both are times within the
same day); false otherwise. |
boolean |
before(Time comparisonTime)
Returns
true if this Time is chronologically
before comparisonTime (assuming both are times within the
same day); false otherwise. |
int |
compareTo(Time comparisonTime)
Compares two
Time objects for chronological ordering
(assuming both are times within the same day). |
boolean |
equals(java.lang.Object o)
|
static Time |
fromCalendar(java.util.Calendar calendar)
Returns the non-null
Time object represented by the
HOUR_OF_DAY and MINUTE fields of
calendar. |
static Time |
fromString(java.lang.String timeString)
Parses a string time in ISO
hh:mm format (the format used
by XML schema's time type) or hhmm format. |
int |
hashCode()
Overridden to ensure consistency with
equals. |
int |
hour()
Returns a number between 0 and 23 (inclusive) representing the hour
component of this
Time. |
int |
minute()
Returns a number between 0 and 59 (inclusive) representing the minute
component of this
Time. |
static Time |
of(int hour,
int minute)
Returns a non-null
Time object representing a time with the
specified hour and minute. |
java.lang.String |
toNumericString()
Returns a non-null, non-empty string representation of this
Time in HHMM format. |
java.lang.String |
toString()
Returns a non-null, non-empty string representation of this
Time in hh:mm format. |
public Time(int hour,
int minute)
Time object representing a time with the
specified hour and minute.
It is usually better to call of(int, int) as that can re-use cached
instances to conserve memory.hour - the hour - a number between 0 and 23 (inclusive).minute - the minute - a number between 0 and 59 (inclusive).java.lang.IllegalArgumentException - if either of the parameters are outside
of their allowed ranges.of(int, int)public int hour()
Time.public int minute()
Time.public static Time of(int hour, int minute)
Time object representing a time with the
specified hour and minute.
This will return Time objects from an internal cache when
possible, to conserve memory.hour - the hour - a number between 0 and 23 (inclusive).minute - the minute - a number between 0 and 59 (inclusive).java.lang.IllegalArgumentException - if either of the parameters are outside
of their allowed ranges.public static Time fromString(java.lang.String timeString) throws java.lang.NumberFormatException
hh:mm format (the format used
by XML schema's time type) or hhmm format.Day object corresponding to the time
represented by timeString.java.lang.NullPointerException - if timeString is
null.java.lang.NumberFormatException - if timeString has an invalid
format.toString(),
toNumericString()public static Time fromCalendar(java.util.Calendar calendar)
Time object represented by the
HOUR_OF_DAY and MINUTE fields of
calendar.java.lang.NullPointerException - if calendar is
null.public java.lang.String toNumericString()
Time in HHMM format.toString(),
fromString(java.lang.String)public java.lang.String toString()
Time in hh:mm format.toString in class java.lang.ObjecttoNumericString(),
fromString(java.lang.String)public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
equals.hashCode in class java.lang.Objectpublic int compareTo(Time comparisonTime)
Time objects for chronological ordering
(assuming both are times within the same day).compareTo in interface java.lang.Comparable<Time>comparisonTime - the Time to be compared. Cannot be
null.Time is before
comparisonTime; zero if this Time is
equal to comparisonTime; or a positive integer if
this Time is after comparisonTime.java.lang.NullPointerException - if comparisonTime is
null.before(net.degreedays.time.Time),
after(net.degreedays.time.Time)public boolean before(Time comparisonTime)
true if this Time is chronologically
before comparisonTime (assuming both are times within the
same day); false otherwise.java.lang.NullPointerException - if comparisonTime is
null.after(net.degreedays.time.Time),
compareTo(net.degreedays.time.Time)public boolean after(Time comparisonTime)
true if this Time is chronologically
after comparisonTime (assuming both are times within the
same day); false otherwise.java.lang.NullPointerException - if comparisonTime is
null.before(net.degreedays.time.Time),
compareTo(net.degreedays.time.Time)
See www.degreedays.net/api/ for more about the Degree Days.net API.
You can sign up for a Degree Days.net API account and read the integration guide that is useful and applicable whether you are using Java or not.