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 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

2018

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

1997

Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Year.html#of-int-



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.