public abstract class AbstractInstant extends Object implements ReadableInstant
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
ReadableInstant interface should be used when different
kinds of date/time objects are to be referenced.
Whenever you want to implement ReadableInstant you should
extend this class.
AbstractInstant itself is thread-safe and immutable, but subclasses may be mutable and not thread-safe.
| 限定符 | 构造器和说明 |
|---|---|
protected |
AbstractInstant()
Constructor.
|
| 限定符和类型 | 方法和说明 |
|---|---|
int |
compareTo(ReadableInstant other)
Compares this object with the specified object for ascending
millisecond instant order.
|
boolean |
equals(Object readableInstant)
Compares this object with the specified object for equality based
on the millisecond instant, chronology and time zone.
|
int |
get(DateTimeField field)
Get the value of one of the fields of a datetime.
|
int |
get(DateTimeFieldType type)
Get the value of one of the fields of a datetime using the chronology of the instant.
|
DateTimeZone |
getZone()
Gets the time zone of the instant from the chronology.
|
int |
hashCode()
Gets a hash code for the instant as defined in
ReadableInstant. |
boolean |
isAfter(long instant)
Is this instant after the millisecond instant passed in
comparing solely by millisecond.
|
boolean |
isAfter(ReadableInstant instant)
Is this instant after the instant passed in
comparing solely by millisecond.
|
boolean |
isAfterNow()
Is this instant after the current instant
comparing solely by millisecond.
|
boolean |
isBefore(long instant)
Is this instant before the millisecond instant passed in
comparing solely by millisecond.
|
boolean |
isBefore(ReadableInstant instant)
Is this instant before the instant passed in
comparing solely by millisecond.
|
boolean |
isBeforeNow()
Is this instant before the current instant
comparing solely by millisecond.
|
boolean |
isEqual(long instant)
Is this instant equal to the millisecond instant passed in
comparing solely by millisecond.
|
boolean |
isEqual(ReadableInstant instant)
Is this instant equal to the instant passed in
comparing solely by millisecond.
|
boolean |
isEqualNow()
Is this instant equal to the current instant
comparing solely by millisecond.
|
boolean |
isSupported(DateTimeFieldType type)
Checks if the field type specified is supported by this instant and chronology.
|
Date |
toDate()
Get the date time as a
java.util.Date. |
DateTime |
toDateTime()
Get this object as a DateTime in the same zone.
|
DateTime |
toDateTime(Chronology chronology)
Get this object as a DateTime using the given chronology and its zone.
|
DateTime |
toDateTime(DateTimeZone zone)
Get this object as a DateTime using the same chronology but a different zone.
|
DateTime |
toDateTimeISO()
Get this object as a DateTime using ISOChronology in the same zone.
|
Instant |
toInstant()
Get this object as an Instant.
|
MutableDateTime |
toMutableDateTime()
Get this object as a MutableDateTime in the same zone.
|
MutableDateTime |
toMutableDateTime(Chronology chronology)
Get this object as a MutableDateTime using the given chronology and its zone.
|
MutableDateTime |
toMutableDateTime(DateTimeZone zone)
Get this object as a MutableDateTime using the same chronology but a different zone.
|
MutableDateTime |
toMutableDateTimeISO()
Get this object as a MutableDateTime using ISOChronology in the same zone.
|
String |
toString()
Output the date time in ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSSZZ).
|
String |
toString(DateTimeFormatter formatter)
Uses the specified formatter to convert this partial to a String.
|
getChronology, getMillispublic DateTimeZone getZone()
getZone 在接口中 ReadableInstantpublic int get(DateTimeFieldType type)
This method uses the chronology of the instant to obtain the value. For example:
DateTime dt = new DateTime(); int year = dt.get(DateTimeFieldType.year());
get 在接口中 ReadableInstanttype - a field type, usually obtained from DateTimeFieldType, not nullIllegalArgumentException - if the field type is nullpublic boolean isSupported(DateTimeFieldType type)
get(DateTimeFieldType).isSupported 在接口中 ReadableInstanttype - a field type, usually obtained from DateTimeFieldTypepublic int get(DateTimeField field)
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());
field - the DateTimeField to use, not nullIllegalArgumentException - if the field is nullpublic Instant toInstant()
toInstant 在接口中 ReadableInstantpublic DateTime toDateTime()
public DateTime toDateTimeISO()
public DateTime toDateTime(DateTimeZone zone)
zone - time zone to apply, or default if nullpublic DateTime toDateTime(Chronology chronology)
chronology - chronology to apply, or ISOChronology if nullpublic MutableDateTime toMutableDateTime()
public MutableDateTime toMutableDateTimeISO()
public MutableDateTime toMutableDateTime(DateTimeZone zone)
zone - time zone to apply, or default if nullpublic MutableDateTime toMutableDateTime(Chronology chronology)
chronology - chronology to apply, or ISOChronology if nullpublic Date toDate()
java.util.Date.
The Date object created has exactly the same millisecond
instant as this object.
public boolean equals(Object readableInstant)
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,
Chronology and instant are equal.
See isEqual(ReadableInstant) for an equals method that
ignores the Chronology and time zone.
All ReadableInstant instances are accepted.
equals 在接口中 ReadableInstantequals 在类中 ObjectreadableInstant - a readable instant to check againstpublic int hashCode()
ReadableInstant.hashCode 在接口中 ReadableInstanthashCode 在类中 Objectpublic int compareTo(ReadableInstant other)
All ReadableInstant instances are accepted.
compareTo 在接口中 Comparable<ReadableInstant>other - a readable instant to check againstNullPointerException - if the object is nullClassCastException - if the object type is not supportedpublic boolean isAfter(long instant)
instant - a millisecond instant to check againstpublic boolean isAfterNow()
public boolean isAfter(ReadableInstant instant)
isAfter 在接口中 ReadableInstantinstant - an instant to check against, null means nowpublic boolean isBefore(long instant)
instant - a millisecond instant to check againstpublic boolean isBeforeNow()
public boolean isBefore(ReadableInstant instant)
isBefore 在接口中 ReadableInstantinstant - an instant to check against, null means nowpublic boolean isEqual(long instant)
instant - a millisecond instant to check againstpublic boolean isEqualNow()
public boolean isEqual(ReadableInstant instant)
isEqual 在接口中 ReadableInstantinstant - an instant to check against, null means nowpublic String toString()
toString 在接口中 ReadableInstanttoString 在类中 Objectpublic String toString(DateTimeFormatter formatter)
formatter - the formatter to use, null means use toString().Copyright © 2020. All rights reserved.