Java Data Type How to - List information for Year








Question

We would like to know how to list information for Year.

Answer

/* w  w  w  .j  a v  a  2 s.  com*/
import java.time.LocalDate;
import java.time.Year;

public class Main {
  public static void main(String[] args) {
    Year currentYear = Year.now();
    Year twoThousand = Year.of(2000);
    boolean isLeap = currentYear.isLeap(); // false
    int length = currentYear.length(); // 365

    // sixtyFourth day of 2014 (2014-03-05)
    LocalDate date = Year.of(2014).atDay(64);

    System.out.println("year: currentYear: " + currentYear);
    System.out.println("year: twoThousand: " + twoThousand);
    System.out.println("year: isLeap: " + isLeap);
    System.out.println("year: length: " + length);
    System.out.println("year: date: " + date);
  }
}

The code above generates the following result.