ZoneId from() method in Java with Examples
The from() method of the ZoneId class used to get instance of ZoneId from TemporalAccessor object passed as parameter.This method obtains a zone based on the TemporalAccessor which represents an arbitrary set of date and time information, which this method converts to an instance of ZoneId.
public static ZoneId from(TemporalAccessor temporal)
Parameters: This method accepts a single parameter temporal which represents the temporal object to convert, It can’t be null.
Return value: This method returns the zone ID, which can not be null.
Exception: This method throws the DateTimeException if this method is unable to convert temporal to a ZoneId.
Below programs illustrate the from() method:
Zone Id got from TemporalAccessor object 2018-10-25T23:12:31.123+02:00[Europe/Paris] is Europe/Paris
Zone Id got from TemporalAccessor object 2018-12-10T18:20:03.637Z[Etc/UTC] is Etc/UTC
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.