Class AbstractInstant
- java.lang.Object
-
- org.joda.time.base.AbstractInstant
-
- All Implemented Interfaces:
java.lang.Comparable<ReadableInstant>,ReadableInstant
- Direct Known Subclasses:
AbstractDateTime,Instant
public abstract class AbstractInstant extends java.lang.Object implements ReadableInstant
AbstractInstant provides the common behaviour for instant classes.This class has no concept of a chronology, all methods work on the millisecond instant.
This class should generally not be used directly by API users. The
ReadableInstantinterface should be used when different kinds of date/time objects are to be referenced.Whenever you want to implement
ReadableInstantyou should extend this class.AbstractInstant itself is thread-safe and immutable, but subclasses may be mutable and not thread-safe.
- Since:
- 1.0
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(ReadableInstant other)Compares this object with the specified object for ascending millisecond instant order.booleanequals(java.lang.Object readableInstant)Compares this object with the specified object for equality based on the millisecond instant, chronology and time zone.intget(DateTimeField field)Get the value of one of the fields of a datetime.intget(DateTimeFieldType type)Get the value of one of the fields of a datetime using the chronology of the instant.DateTimeZonegetZone()Gets the time zone of the instant from the chronology.inthashCode()Gets a hash code for the instant as defined inReadableInstant.booleanisAfter(long instant)Is this instant after the millisecond instant passed in comparing solely by millisecond.booleanisAfter(ReadableInstant instant)Is this instant after the instant passed in comparing solely by millisecond.booleanisAfterNow()Is this instant after the current instant comparing solely by millisecond.booleanisBefore(long instant)Is this instant before the millisecond instant passed in comparing solely by millisecond.booleanisBefore(ReadableInstant instant)Is this instant before the instant passed in comparing solely by millisecond.booleanisBeforeNow()Is this instant before the current instant comparing solely by millisecond.booleanisEqual(long instant)Is this instant equal to the millisecond instant passed in comparing solely by millisecond.booleanisEqual(ReadableInstant instant)Is this instant equal to the instant passed in comparing solely by millisecond.booleanisEqualNow()Is this instant equal to the current instant comparing solely by millisecond.booleanisSupported(DateTimeFieldType type)Checks if the field type specified is supported by this instant and chronology.java.util.DatetoDate()Get the date time as ajava.util.Date.DateTimetoDateTime()Get this object as a DateTime in the same zone.DateTimetoDateTime(Chronology chronology)Get this object as a DateTime using the given chronology and its zone.DateTimetoDateTime(DateTimeZone zone)Get this object as a DateTime using the same chronology but a different zone.DateTimetoDateTimeISO()Get this object as a DateTime using ISOChronology in the same zone.InstanttoInstant()Get this object as an Instant.MutableDateTimetoMutableDateTime()Get this object as a MutableDateTime in the same zone.MutableDateTimetoMutableDateTime(Chronology chronology)Get this object as a MutableDateTime using the given chronology and its zone.MutableDateTimetoMutableDateTime(DateTimeZone zone)Get this object as a MutableDateTime using the same chronology but a different zone.MutableDateTimetoMutableDateTimeISO()Get this object as a MutableDateTime using ISOChronology in the same zone.java.lang.StringtoString()Output the date time in ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSSZZ).java.lang.StringtoString(DateTimeFormatter formatter)Uses the specified formatter to convert this partial to a String.-
Methods inherited from interface org.joda.time.ReadableInstant
getChronology, getMillis
-
-
-
-
Method Detail
-
getZone
public DateTimeZone getZone()
Gets the time zone of the instant from the chronology.- Specified by:
getZonein interfaceReadableInstant- Returns:
- the DateTimeZone that the instant is using, never null
-
get
public int get(DateTimeFieldType type)
Get the value of one of the fields of a datetime using the chronology of the instant.This method uses the chronology of the instant to obtain the value. For example:
DateTime dt = new DateTime(); int year = dt.get(DateTimeFieldType.year());
- Specified by:
getin interfaceReadableInstant- 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
public boolean isSupported(DateTimeFieldType type)
Checks if the field type specified is supported by this instant and chronology. This can be used to avoid exceptions inget(DateTimeFieldType).- Specified by:
isSupportedin interfaceReadableInstant- Parameters:
type- a field type, usually obtained from DateTimeFieldType- Returns:
- true if the field type is supported
-
get
public int get(DateTimeField field)
Get the value of one of the fields of a datetime.This could be used to get a field using a different Chronology. For example:
Instant dt = new Instant(); int gjYear = dt.get(Chronology.getCoptic().year());
- Parameters:
field- the DateTimeField to use, not null- Returns:
- the value
- Throws:
java.lang.IllegalArgumentException- if the field is null
-
toInstant
public Instant toInstant()
Get this object as an Instant.- Specified by:
toInstantin interfaceReadableInstant- Returns:
- an Instant using the same millis
-
toDateTime
public DateTime toDateTime()
Get this object as a DateTime in the same zone.- Returns:
- a DateTime using the same millis
-
toDateTimeISO
public DateTime toDateTimeISO()
Get this object as a DateTime using ISOChronology in the same zone.- Returns:
- a DateTime using the same millis with ISOChronology
-
toDateTime
public DateTime toDateTime(DateTimeZone zone)
Get this object as a DateTime using the same chronology but a different zone.- Parameters:
zone- time zone to apply, or default if null- Returns:
- a DateTime using the same millis
-
toDateTime
public DateTime toDateTime(Chronology chronology)
Get this object as a DateTime using the given chronology and its zone.- Parameters:
chronology- chronology to apply, or ISOChronology if null- Returns:
- a DateTime using the same millis
-
toMutableDateTime
public MutableDateTime toMutableDateTime()
Get this object as a MutableDateTime in the same zone.- Returns:
- a MutableDateTime using the same millis
-
toMutableDateTimeISO
public MutableDateTime toMutableDateTimeISO()
Get this object as a MutableDateTime using ISOChronology in the same zone.- Returns:
- a MutableDateTime using the same millis with ISOChronology
-
toMutableDateTime
public MutableDateTime toMutableDateTime(DateTimeZone zone)
Get this object as a MutableDateTime using the same chronology but a different zone.- Parameters:
zone- time zone to apply, or default if null- Returns:
- a MutableDateTime using the same millis
-
toMutableDateTime
public MutableDateTime toMutableDateTime(Chronology chronology)
Get this object as a MutableDateTime using the given chronology and its zone.- Parameters:
chronology- chronology to apply, or ISOChronology if null- Returns:
- a MutableDateTime using the same millis
-
toDate
public java.util.Date toDate()
Get the date time as ajava.util.Date.The
Dateobject created has exactly the same millisecond instant as this object.- Returns:
- a Date initialised with this datetime
-
equals
public boolean equals(java.lang.Object readableInstant)
Compares this object with the specified object for equality based on the millisecond instant, chronology and time zone.Two objects which represent the same instant in time, but are in different time zones (based on time zone id), will be considered to be different. Only two objects with the same
DateTimeZone,Chronologyand instant are equal.See
isEqual(ReadableInstant)for an equals method that ignores the Chronology and time zone.All ReadableInstant instances are accepted.
- Specified by:
equalsin interfaceReadableInstant- 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
public int hashCode()
Gets a hash code for the instant as defined inReadableInstant.- Specified by:
hashCodein interfaceReadableInstant- Overrides:
hashCodein classjava.lang.Object- Returns:
- a suitable hash code
-
compareTo
public int compareTo(ReadableInstant other)
Compares this object with the specified object for ascending millisecond instant order. This ordering is inconsistent with equals, as it ignores the Chronology.All ReadableInstant instances are accepted.
- Specified by:
compareToin interfacejava.lang.Comparable<ReadableInstant>- Parameters:
other- a readable instant to check against- Returns:
- negative value if this is less, 0 if equal, or positive value if greater
- Throws:
java.lang.NullPointerException- if the object is nulljava.lang.ClassCastException- if the object type is not supported
-
isAfter
public boolean isAfter(long instant)
Is this instant after the millisecond instant passed in comparing solely by millisecond.- Parameters:
instant- a millisecond instant to check against- Returns:
- true if this instant is after the instant passed in
-
isAfterNow
public boolean isAfterNow()
Is this instant after the current instant comparing solely by millisecond.- Returns:
- true if this instant is after the current instant
-
isAfter
public boolean isAfter(ReadableInstant instant)
Is this instant after the instant passed in comparing solely by millisecond.- Specified by:
isAfterin interfaceReadableInstant- Parameters:
instant- an instant to check against, null means now- Returns:
- true if the instant is after the instant passed in
-
isBefore
public boolean isBefore(long instant)
Is this instant before the millisecond instant passed in comparing solely by millisecond.- Parameters:
instant- a millisecond instant to check against- Returns:
- true if this instant is before the instant passed in
-
isBeforeNow
public boolean isBeforeNow()
Is this instant before the current instant comparing solely by millisecond.- Returns:
- true if this instant is before the current instant
-
isBefore
public boolean isBefore(ReadableInstant instant)
Is this instant before the instant passed in comparing solely by millisecond.- Specified by:
isBeforein interfaceReadableInstant- Parameters:
instant- an instant to check against, null means now- Returns:
- true if the instant is before the instant passed in
-
isEqual
public boolean isEqual(long instant)
Is this instant equal to the millisecond instant passed in comparing solely by millisecond.- Parameters:
instant- a millisecond instant to check against- Returns:
- true if this instant is equal to the instant passed in
-
isEqualNow
public boolean isEqualNow()
Is this instant equal to the current instant comparing solely by millisecond.- Returns:
- true if this instant is equal to the current instant
-
isEqual
public boolean isEqual(ReadableInstant instant)
Is this instant equal to the instant passed in comparing solely by millisecond.- Specified by:
isEqualin interfaceReadableInstant- Parameters:
instant- an instant to check against, null means now- Returns:
- true if the instant is equal to the instant passed in
-
toString
public java.lang.String toString()
Output the date time in ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSSZZ).- Specified by:
toStringin interfaceReadableInstant- Overrides:
toStringin classjava.lang.Object- Returns:
- ISO8601 time formatted string, not null
-
toString
public java.lang.String toString(DateTimeFormatter formatter)
Uses the specified formatter to convert this partial to a String.- Parameters:
formatter- the formatter to use, null means usetoString().- Returns:
- the formatted string, not null
- Since:
- 1.1
-
-