Tuesday, June 9, 2026
HomeLanguagesJavaYear of() method in Java with Examples

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:




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

RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6895 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7018 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS