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 the only parameter according to the proleptic ISO calendar system.
Return Value: It returns an instance of Year.
Exception: It throws DateTimeException if the year passed as argument is found to be invalid according to the proleptic ISO calendar system.
Below programs illustrate the length() method of Year in Java:
Program 1:
// Program to illustrate the of() method   import java.util.*; import java.time.*;   public class GfG {     public static void main(String[] args)     {         // Create a valid Year object         // using of() method         Year thisYear = Year.of( 2018 );           // Print the year object         System.out.println(thisYear);     } } |
2018
Program 2:
// Program to illustrate the of() method   import java.util.*; import java.time.*;   public class GfG {     public static void main(String[] args)     {         // Create a valid Year object         // using of() method         Year thisYear = Year.of( 1997 );           // Print the year object         System.out.println(thisYear);     } } |
1997
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Year.html#of-int-
[…] java.time.Year class represents a year in the ISO-8601 calendar system, such as 2021. Year is an immutable […]