Java Year class
Java Year class is an immutable date-time object that represents a year. It inherits the Object class and implements the Comparable interface.
Java Year class declaration
Let's see the declaration of java.time.Year class.
Methods of Java Year
Method |
Description |
LocalDate atDay(int dayOfYear) |
It is used to combine this year with a day-of-year to create a LocalDate. |
String format(DateTimeFormatter formatter) |
It is used to format this year using the specified formatter. |
int get(TemporalField field) |
It is used to get the value of the specified field from this year as an int. |
boolean isAfter(Year other) |
It is used to check if this year is after the specified year. |
boolean isBefore(Year other) |
It is used to check if this year is before the specified year. |
boolean isLeap() |
It is used to check if the year is a leap year, according to the ISO proleptic calendar system rules. |
int length() |
It is used to get the length of this year in days. |
static Year now() |
It is used to obtain the current year from the system clock in the default time-zone. |
Java Year Example: now()
Test it Now
Output:
Java Year Example: atDay()
Test it Now
Output:
Java Year Example: length()
Test it Now
Output:
Java Year Example: isLeap()
Test it Now
Output:
|