Year from() Method in Java with Examples Last Updated : 16 Jan, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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. Syntax: 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: Program 1: Java // Java program to demonstrate // Year.from() method import java.time.*; public class GFG { public static void main(String[] args) { // create a temporal object LocalDate date = LocalDate.parse("2007-12-03"); // print instance System.out.println("LocalDate :" + date); // apply from method of Year class Year year = Year.from(date); // print instance System.out.println("Year get from" + " method: " + year); } } Output: LocalDate :2007-12-03 Year get from method: 2007 Program 2: Java // Java program to demonstrate // Year.from() method import java.time.*; public class GFG { public static void main(String[] args) { // create a temporal object LocalDate ins = LocalDate.parse("2018-11-27"); // print instance System.out.println("LocalDate :" + ins); // apply from method of Year class Year year = Year.from(ins); // print instance System.out.println("Year get from" + " method: " + year); } } Output: LocalDate :2018-11-27 Year get from method: 2018 References: https://docs.oracle.com/javase/10/docs/api/java/time/Year.html#from(java.time.temporal.Temporal) Comment More infoAdvertise with us Next Article Year now() method in Java with examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-time package Java-Year Practice Tags : Java Similar Reads Year format() method in Java with Examples The format() method of Year class in Java is used to format the current Year object according to the DateTimeFormatter passed to it as a parameter. Syntax: public String format(DateTimeFormatter formatter) Parameter: This method accepts a single parameter formatter. It specifies a DateTimeFormatter 2 min read Year get() method in Java with Examples get() method of the Year class used to get the value for the specified field passed as parameter from this Year as an integer value. This method queries this year 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 is not su 2 min read Year of() method in Java with Examples The of() method of Year class in Java is used to return an Year instance. It accepts an year according to the proleptic ISO calendar system and returns an instance of Year with the specified isoYear. Syntax: public static Year of(int isoYear) Parameter: It accepts a single integral value isoYear as 1 min read Year now() method in Java with examples The now() method of Year class in Java is used to return the current year from the system clock in the default time-zone. Syntax: public static Year now() or, public static Year now(Clock clock) or, public static Year now(ZoneId zone) Parameter: The parameter is optional for this method as shown in 2 min read Year hashCode() method in Java with Examples The hashCode() method of Year class in Java is used to get a suitable hash code for the current Year object. Syntax: public int hashCode() Parameter: This method does not accepts any parameter. Return Value: It returns a suitable integral hash code for the year object with which it is used. It never 1 min read Year with() Method in Java with Examples In Year class, there are two types of with() method depending upon the parameters passed to it. with(TemporalAdjuster adjuster) with(TemporalAdjuster adjuster) method of the Year class used to adjusted this Year using TemporalAdjuster and after adjustment returns the copy of adjusted Year.The adjust 3 min read Like