Interface ReadableInstant
-
- All Superinterfaces:
java.lang.Comparable<ReadableInstant>
- All Known Subinterfaces:
ReadableDateTime,ReadWritableDateTime,ReadWritableInstant
- All Known Implementing Classes:
AbstractDateTime,AbstractInstant,BaseDateTime,DateMidnight,DateTime,Instant,MutableDateTime
public interface ReadableInstant extends java.lang.Comparable<ReadableInstant>
Defines an instant in the datetime continuum. This interface expresses the datetime as milliseconds from 1970-01-01T00:00:00Z.The implementation of this interface may be mutable or immutable. This interface only gives access to retrieve data, never to change it.
Methods in your application should be defined using
ReadableInstantas a parameter if the method only wants to read the instant without needing to know the specific datetime fields.The
compareTomethod is no longer defined in this class in version 2.0. Instead, the definition is simply inherited from theComparableinterface. This approach is necessary to preserve binary compatibility. The definition of the comparison is ascending order by millisecond instant. Implementors are recommended to extendAbstractInstantinstead of this interface.- Since:
- 1.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanequals(java.lang.Object readableInstant)Compares this object with the specified object for equality based on the millisecond instant and the Chronology.intget(DateTimeFieldType type)Get the value of one of the fields of a datetime.ChronologygetChronology()Gets the chronology of the instant.longgetMillis()Get the value as the number of milliseconds since the epoch, 1970-01-01T00:00:00Z.DateTimeZonegetZone()Gets the time zone of the instant from the chronology.inthashCode()Gets a hash code for the instant that is compatible with the equals method.booleanisAfter(ReadableInstant instant)Is this instant after the instant passed in comparing solely by millisecond.booleanisBefore(ReadableInstant instant)Is this instant before the instant passed in comparing solely by millisecond.booleanisEqual(ReadableInstant instant)Is this instant equal to the instant passed in comparing solely by millisecond.booleanisSupported(DateTimeFieldType field)Checks whether the field type specified is supported by this implementation.InstanttoInstant()Get the value as a simple immutableInstantobject.java.lang.StringtoString()Get the value as a String in a recognisable ISO8601 format.
-
-
-
Method Detail
-
getMillis
long getMillis()
Get the value as the number of milliseconds since the epoch, 1970-01-01T00:00:00Z.- Returns:
- the value as milliseconds
-
getChronology
Chronology getChronology()
Gets the chronology of the instant.The
Chronologyprovides conversion from the millisecond value to meaningful fields in a particular calendar system.- Returns:
- the Chronology, never null
-
getZone
DateTimeZone getZone()
Gets the time zone of the instant from the chronology.- Returns:
- the DateTimeZone that the instant is using, never null
-
get
int get(DateTimeFieldType type)
Get the value of one of the fields of a datetime.This method uses the chronology of the instant to obtain the value.
- Parameters:
type- a field type, usually obtained from DateTimeFieldType, not null- Returns:
- the value of that field
- Throws:
java.lang.IllegalArgumentException- if the field type is null
-
isSupported
boolean isSupported(DateTimeFieldType field)
Checks whether the field type specified is supported by this implementation.- Parameters:
field- the field type to check, may be null which returns false- Returns:
- true if the field is supported
-
toInstant
Instant toInstant()
Get the value as a simple immutableInstantobject.This can be useful if you don't trust the implementation of the interface to be well-behaved, or to get a guaranteed immutable object.
- Returns:
- the value as an
Instantobject
-
isEqual
boolean isEqual(ReadableInstant instant)
Is this instant equal to the instant passed in comparing solely by millisecond.- Parameters:
instant- an instant to check against, null means now- Returns:
- true if the instant is equal to the instant passed in
-
isAfter
boolean isAfter(ReadableInstant instant)
Is this instant after the instant passed in comparing solely by millisecond.- Parameters:
instant- an instant to check against, null means now- Returns:
- true if the instant is after the instant passed in
-
isBefore
boolean isBefore(ReadableInstant instant)
Is this instant before the instant passed in comparing solely by millisecond.- Parameters:
instant- an instant to check against, null means now- Returns:
- true if the instant is before the instant passed in
-
equals
boolean equals(java.lang.Object readableInstant)
Compares this object with the specified object for equality based on the millisecond instant and the Chronology. All ReadableInstant instances are accepted.To compare two instants for absolute time (ie. UTC milliseconds ignoring the chronology), use
isEqual(ReadableInstant)orComparable.compareTo(Object).- Overrides:
equalsin classjava.lang.Object- Parameters:
readableInstant- a readable instant to check against- Returns:
- true if millisecond and chronology are equal, false if not or the instant is null or of an incorrect type
-
hashCode
int hashCode()
Gets a hash code for the instant that is compatible with the equals method.The formula used must be as follows:
((int) (getMillis() ^ (getMillis() >>> 32))) + (getChronology().hashCode())
- Overrides:
hashCodein classjava.lang.Object- Returns:
- a hash code as defined above
-
toString
java.lang.String toString()
Get the value as a String in a recognisable ISO8601 format.The string output is in ISO8601 format to enable the String constructor to correctly parse it.
- Overrides:
toStringin classjava.lang.Object- Returns:
- the value as an ISO8601 string
-
-