Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Year of() method in Java with Examples

  • Last Updated : 27 Nov, 2018

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:

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.

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);
    }
}
Output:
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);
    }
}
Output:
1997

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!