Period getYears()
gets the amount of years of this period. This returns the years unit.
getYears
has the following syntax.
public int getYears()
The following example shows how to use getYears
.
import java.time.Period; // ww w . j a v a 2 s.co m public class Main { public static void main(String[] args) { Period p = Period.ofMonths(1); System.out.println(p.getYears()); } }
The code above generates the following result.