from() method of the Year class used to get instance of Year from TemporalAccessor object passed as parameter. A TemporalAccessor represents an arbitrary set of date and time information and this method helps to get a year object based on the specified TemporalAccessor object.
public static Year from(TemporalAccessor temporal)
Parameters: This method accepts temporal as parameter which is the temporal object. It should not be null.
Return value: This method returns the year object.
Exception: This method throws following Exceptions:
- DateTimeException – if unable to convert to a Year.
Below programs illustrate the from() method:
LocalDate :2007-12-03 Year get from method: 2007
LocalDate :2018-11-27 Year get from method: 2018
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.