Instant from() method in Java with Examples Last Updated : 03 Apr, 2023 Comments Improve Suggest changes Like Article Like Report The from() method of Instant class helps to get instance of instant from TemporalAccessor object passed as parameter. A TemporalAccessor represents an arbitrary set of date and time information and this method helps to get an instant based on the specified TemporalAccessor object. The conversion of TemporalAccessor object to instant extracts the INSTANT_SECONDS and NANO_OF_SECOND fields. Syntax: public static Instant from(TemporalAccessor temporal) Parameters: This method accepts only one parameter temporal which represents the temporal object. It should not be null. Returns: This method returns Instant object from the TemporalAccessor Object. It should not be null. Exception: This method throws DateTimeException if method is unable to convert temporal object to an Instant. Below programs illustrate the from() method: Program 1: Java // Java program to demonstrate // Instant.from() method import java.time.*; public class GFG { public static void main(String[] args) { // create a ZonedDateTime object ZonedDateTime zonedDateTime = ZonedDateTime.now(); // print Value System.out.println("ZonedDateTime: " + zonedDateTime); // create a Instant object using // from() method Instant result = Instant.from(zonedDateTime); // print result System.out.println("Instant: " + result); } } Output:ZonedDateTime: 2018-11-27T04:58:47.691Z[Etc/UTC] Instant: 2018-11-27T04:58:47.691Z Program 2: Java // Java program to demonstrate // Instant.from() method import java.time.*; public class GFG { public static void main(String[] args) { // create a OffsetDateTime object OffsetDateTime offset = OffsetDateTime.now(); // print Value System.out.println("OffsetDateTime: " + offset); // apply from() method Instant result = Instant.from(offset); // print result System.out.println("Instant: " + result); } } Output:OffsetDateTime: 2018-11-27T04:58:50.588Z Instant: 2018-11-27T04:58:50.588Z References: https://docs.oracle.com/javase/10/docs/api/java/time/Instant.html#from(java.time.temporal.TemporalAccessor) Comment More infoAdvertise with us Next Article Instant from() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java - util package Java-Functions Java-Instant Practice Tags : Java Similar Reads Instant get() method in Java with Examples The get() method of Instant class helps to get the value for the specified field passed as parameter from this instant as an integer value. This method queries this instant for the value of the field and the returned value will always be within the valid range of values for the field. When the field 2 min read Instant now() Method in Java with Examples In Instant class, there are two types of now() method depending upon the parameters passed to it. now() now() method of a Instant class used to obtain the current instant from the system UTC clock.This method will return instant based on system UTC clock. Syntax: public static Instant now() Paramete 2 min read Instant getNano() method in Java with Examples The getNano() method of Instant class is used to return the number of nanoseconds later in the time-line represented in this instant, from the start of the second. The nanosecond-of-second value which measures the total number of nanoseconds from the second value returned by getEpochSecond(). Syntax 2 min read Instant plus() method in Java with Examples In Instant class, there are two types of plus() method depending upon the parameters passed to it. plus(long amountToAdd, TemporalUnit unit) plus() method of a Instant class used to return a copy of this instant with the specified amount of unit added.If it is not possible to add the amount, because 2 min read Instant with() Method in Java with Examples In Instant class, there are two types of with() method depending upon the parameters passed to it. with(TemporalAdjuster adjuster) with(TemporalAdjuster adjuster) method of the Instant class used to adjusted this instant using TemporalAdjuster and after adjustment returns the copy of adjusted instan 3 min read Like