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 TempralAccessor object to instant extracts the INSTANT_SECONDS and NANO_OF_SECOND fields.
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:
ZonedDateTime: 2018-11-27T04:58:47.691Z[Etc/UTC] Instant: 2018-11-27T04:58:47.691Z
OffsetDateTime: 2018-11-27T04:58:50.588Z Instant: 2018-11-27T04:58:50.588Z
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.