Java 8 Instant class

The java.time.Instant class is used to represent the specific moment on the time line

Java Instant class methods

MethodDescription
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.

Example

package com.w3spoint;
 
import java.time.Instant;
 
public class TestExample {
	public static void main(String args[]){
	    Instant instant = Instant.parse("2018-04-03T10:32:40.00Z");  
	    System.out.println(instant);  
 
	    //now() method
	    instant = Instant.now();  
	    System.out.println(instant); 	    
	}  
}

Output

2018-04-03T10:32:40Z
2018-04-15T14:16:19.521Z
Content Protection by DMCA.com
Please Share