Java Instant class

Java Instant class is used to represent the specific moment on the time line. It inherits the Object class and implements the Comparable interface.


Java Instant class declaration

Let's see the declaration of java.time.Instant class.

Methods of Java Instant

Method Description
Temporal adjustInto(Temporal temporal). It is used to adjust the specified temporal object to have this instant.
int get(TemporalField field) It is used to get the value of the specified field from this instant as an int.
boolean isSupported(TemporalField field) It is used to check if the specified field is supported.
Instant minus(TemporalAmount amountToSubtract) It is used to return a copy of this instant with the specified amount subtracted.
static Instant now() It is used to obtain the current instant from the system clock.
static Instant parse(CharSequence text) It is used to obtain an instance of Instant from a text string such as 2007-12-03T10:15:30.00Z.
Instant plus(TemporalAmount amountToAdd) It is used to return a copy of this instant with the specified amount added.
Instant with(TemporalAdjuster adjuster) It is used to return an adjusted copy of this instant.

Java Instant Example: parse()

Test it Now

Output:

2017-02-03T10:37:30Z

Java Instant Example: now()

Test it Now

Output:

2017-02-03T06:11:01.194Z

Java Instant Example: minus()

Test it Now

Output:

2016-10-01T11:25:30Z

Java Instant Example: plus()

Test it Now

Output:

2017-06-08T11:25:30Z

Java Instant Example: isSupported()

Test it Now

Output:

true
false




Contact US

Email:[email protected]

Java Instant
10/30