Java Year class

Introduction

A Year represents a year, for example, 2020, 2013, etc.

import java.time.Year;

public class Main {
  public static void main(String[] args) {
    // Use Year/*from   w  w w  .j ava  2  s. co  m*/
    Year y1 = Year.of(2020); 
    System.out.println(y1);
    Year y2 = y1.minusYears(1); 
    System.out.println(y2);
    Year y3 = y1.plusYears(1); 
    System.out.println(y3);
    

  }
}



PreviousNext

Related