|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objecttime.Instant
public final class Instant
Instant is the implementation of a fully immutable instant in time. An instant in time represents an event that have theorically no duration.
An Instant represents a point in the universal line of time, which is supposed to be the same everywhere in the whole Universe. (This is a Newtonian vision of the Time which is known as approximated since Einstein's Theory of Relativity, which shows that space and time are linked, but this approximation is fine for us).
Here some examples of famous instants:
To ensure compatibility with existing classes in Java, Instant are implemented as milliseconds since the Java Epoch of 1970-01-01 00:00:00 GMT, but please note that this is only an implementation detail. The current implementation is then milliseconds accurate, but future implementation may offer finer accuracy (nanoseconds).
Instants are Comparable, and their natural order is the chronological order.
Two Instants are equals if they represent the same instant in time (they occur at exactly the same moment).
As Instant are immutable, they are fully thread-safe.
| Field Summary | |
|---|---|
static Instant |
APOCALYPSE
The maximum value of an Instant, which will happen about 292 millions of years after the Epoch. |
static Instant |
BIG_BANG
The minimum value of an Instant, about 292 millions of years before the Epoch. |
static Instant |
EPOCH
The famous Epoch. (1970-01-01 00:00:00) |
| Constructor Summary | |
|---|---|
Instant()
Create a new Instant, which represents the current time (now). |
|
Instant(java.util.Date date)
Create a new Instant. |
|
Instant(long millis)
Create a new Instant. |
|
| Method Summary | |
|---|---|
java.util.Date |
asImmutableDate()
Return a java.util.Date view of this Instant. |
int |
compareTo(Instant otherInstant)
Compare two instants chronogically. |
boolean |
equals(java.lang.Object obj)
Compare two instants for equality. |
long |
getMillis()
Returns the number of milliseconds since the Epoch represented by this Instant object. |
long |
getNanos()
Returns 0L in this current implementation.. |
int |
hashCode()
Returns a hash code value for this object. |
long |
millisBetween(Instant otherInstant)
Compute the number of milliseconds between this instant and another instant. |
java.lang.String |
toString()
Convert this Instant to a String. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final Instant EPOCH
public static final Instant BIG_BANG
public static final Instant APOCALYPSE
| Constructor Detail |
|---|
public Instant()
public Instant(long millis)
millis - number of milliseconds since the Epoch of the Instant to createpublic Instant(java.util.Date date)
date - Date of the Instant to create.
java.lang.NullPointerException - if date is null.| Method Detail |
|---|
public int compareTo(Instant otherInstant)
compareTo in interface java.lang.Comparable<Instant>otherInstant - the instant to be compared.
java.lang.NullPointerException - if otherInstant is null.public long millisBetween(Instant otherInstant)
If this instant occurs after the other instant, the result is positive. If this instant occurs before the other instant, the result is negative.
java.lang.NullPointerException - if otherInstant is null.public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectobj - the object to compare with.
public int hashCode()
hashCode in class java.lang.Objectpublic java.util.Date asImmutableDate()
The returned date is immutable, as the returned class is a subclass of java.util.Date which all mutating methods have been overidden to throw a UnsupportedOperationException.
public long getMillis()
public long getNanos()
public java.lang.String toString()
toString in class java.lang.Object
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||