java.lang.Object | ||
↳ | org.joda.time.base.AbstractInstant | |
↳ | org.joda.time.Instant |
Instant is the standard implementation of a fully immutable instant in time.
Instant
is an implementation of ReadableInstant
.
As with all instants, it represents an exact point on the time-line,
but limited to the precision of milliseconds. An Instant
should be used to represent a point in time irrespective of any other
factor, such as chronology or time zone.
Internally, the class holds one piece of data, the instant as milliseconds from the Java epoch of 1970-01-01T00:00:00Z.
For example, an Instant can be used to compare two DateTime
objects irrespective of chronology or time zone.
boolean sameInstant = dt1.toInstant().equals(dt2.toInstant());Note that the following code will also perform the same check:
boolean sameInstant = dt1.isEqual(dt2);
Instant is thread-safe and immutable.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs an instance set to the current system millisecond time.
| |||||||||||
Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z.
| |||||||||||
Constructs an instance from an Object that represents a datetime.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Gets the chronology of the instant, which is ISO in the UTC zone.
| |||||||||||
Gets the milliseconds of the instant.
| |||||||||||
Gets a copy of this instant with the specified duration taken away.
| |||||||||||
Gets a copy of this instant with the specified duration taken away.
| |||||||||||
Gets a copy of this instant with the specified duration added.
| |||||||||||
Gets a copy of this instant with the specified duration added.
| |||||||||||
Get this object as a DateTime using ISOChronology in the default zone.
| |||||||||||
This method is deprecated.
Use toDateTime() as it is identical
| |||||||||||
Get this object as an Instant by returning
this . | |||||||||||
Get this object as a MutableDateTime using ISOChronology in the default zone.
| |||||||||||
This method is deprecated.
Use toMutableDateTime() as it is identical
| |||||||||||
Gets a copy of this instant with the specified duration added.
| |||||||||||
Gets a copy of this instant with the specified duration added.
| |||||||||||
Gets a copy of this instant with different millis.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.joda.time.base.AbstractInstant
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.lang.Comparable
| |||||||||||
From interface
org.joda.time.ReadableInstant
|
Constructs an instance set to the current system millisecond time.
Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z.
instant | the milliseconds from 1970-01-01T00:00:00Z |
---|
Constructs an instance from an Object that represents a datetime.
The recognised object types are defined in ConverterManager
and
include String, Calendar and Date.
instant | the datetime object, null means now |
---|
IllegalArgumentException | if the instant is invalid |
---|
Gets the chronology of the instant, which is ISO in the UTC zone.
This method returns getInstanceUTC()
which
corresponds to the definition of the Java epoch 1970-01-01T00:00:00Z.
Gets the milliseconds of the instant.
Gets a copy of this instant with the specified duration taken away.
If the amount is zero or null, then this
is returned.
duration | the duration to reduce this instant by |
---|
ArithmeticException | if the new instant exceeds the capacity of a long |
---|
Gets a copy of this instant with the specified duration taken away.
If the amount is zero or null, then this
is returned.
duration | the duration to reduce this instant by |
---|
ArithmeticException | if the new instant exceeds the capacity of a long |
---|
Gets a copy of this instant with the specified duration added.
If the amount is zero or null, then this
is returned.
duration | the duration to add to this one, null means zero |
---|
ArithmeticException | if the new instant exceeds the capacity of a long |
---|
Gets a copy of this instant with the specified duration added.
If the amount is zero or null, then this
is returned.
duration | the duration to add to this one |
---|
ArithmeticException | if the new instant exceeds the capacity of a long |
---|
Get this object as a DateTime using ISOChronology in the default zone.
This method returns a DateTime object in the default zone. This differs from the similarly named method on DateTime, DateMidnight or MutableDateTime which retains the time zone. The difference is because Instant really represents a time without a zone, thus calling this method we really have no zone to 'retain' and hence expect to switch to the default zone.
This method definition preserves compatability with earlier versions of Joda-Time.
This method is deprecated.
Use toDateTime() as it is identical
Get this object as a DateTime using ISOChronology in the default zone.
This method is identical to toDateTime()
.
This method returns a DateTime object in the default zone. This differs from the similarly named method on DateTime, DateMidnight or MutableDateTime which retains the time zone. The difference is because Instant really represents a time without a zone, thus calling this method we really have no zone to 'retain' and hence expect to switch to the default zone.
This method definition preserves compatability with earlier versions of Joda-Time.
Get this object as a MutableDateTime using ISOChronology in the default zone.
This method returns a MutableDateTime object in the default zone. This differs from the similarly named method on DateTime, DateMidnight or MutableDateTime which retains the time zone. The difference is because Instant really represents a time without a zone, thus calling this method we really have no zone to 'retain' and hence expect to switch to the default zone.
This method definition preserves compatability with earlier versions of Joda-Time.
This method is deprecated.
Use toMutableDateTime() as it is identical
Get this object as a MutableDateTime using ISOChronology in the default zone.
This method is identical to toMutableDateTime()
.
This method returns a MutableDateTime object in the default zone. This differs from the similarly named method on DateTime, DateMidnight or MutableDateTime which retains the time zone. The difference is because Instant really represents a time without a zone, thus calling this method we really have no zone to 'retain' and hence expect to switch to the default zone.
This method definition preserves compatability with earlier versions of Joda-Time.
Gets a copy of this instant with the specified duration added.
If the addition is zero, then this
is returned.
durationToAdd | the duration to add to this one |
---|---|
scalar | the amount of times to add, such as -1 to subtract once |
ArithmeticException | if the new instant exceeds the capacity of a long |
---|
Gets a copy of this instant with the specified duration added.
If the addition is zero, then this
is returned.
durationToAdd | the duration to add to this one, null means zero |
---|---|
scalar | the amount of times to add, such as -1 to subtract once |
ArithmeticException | if the new instant exceeds the capacity of a long |
---|
Gets a copy of this instant with different millis.
The returned object will be either be a new Instant or this
.
newMillis | the new millis, from 1970-01-01T00:00:00Z |
---|