Java 8 Year class

The java.time.Year class is an immutable date-time object that represents a year.

Java Year class methods

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.

Example

package com.w3spoint;
 
import java.time.Year;
 
public class TestExample {
	public static void main(String args[]){
	    Year year = Year.now();  
	    System.out.println(year); 
 
	    //atDay() method
	    System.out.println(year.atDay(223));
 
	    //length() method
	    System.out.println(year.length());
 
	    //isLeap() method
	    System.out.println(year.isLeap());
 
	}  
}

Output

2018
2018-08-11
365
false
Please follow and like us:
Content Protection by DMCA.com