The from(TemporalAccessor) method of ZoneOffset Class in java.time package is used to obtain an instance of ZoneOffset using the offset in temporalAccessor passed as the parameter. This method takes the temporalAccessor as parameter in the form of TemporalAccessor and converts it into the ZoneOffset.
public static ZoneOffset from(TemporalAccessor temporalAccessor)
Parameters: This method accepts a parameter temporalAccessor which is TemporalAccessor to be converted into an ZoneOffset instance.
Return Value: This method returns a ZoneOffset instance parsed from the specified temporalAccessor.
Exception: This method throws DateTimeException if the temporalAccessor is invalid.
Below examples illustrate the ZoneOffset.from() method:
Example 2: To demonstrate DateTimeException
java.time.DateTimeException: Unable to obtain ZoneOffset from TemporalAccessor: 2018-12-11 of type java.time.LocalDate
Reference: Oracle Doc
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.