YearMonth getYear()
gets the year field.
getYear
has the following syntax.
public int getYear()
The following example shows how to use getYear
.
import java.time.YearMonth; //w w w . j a va 2s. com public class Main { public static void main(String[] args) { YearMonth y = YearMonth.now(); int m = y.getYear(); System.out.println(m); } }
The code above generates the following result.