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:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
Year thisYear = Year.of( 2018 );
System.out.println(thisYear);
}
}
|
Program 2:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
Year thisYear = Year.of( 1997 );
System.out.println(thisYear);
}
}
|
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Year.html#of-int-
Last Updated :
27 Nov, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...