Period getYears() example
Description
Period getYears()
gets the amount of years of this period. This returns the years unit.
Syntax
getYears
has the following syntax.
public int getYears()
Example
The following example shows how to use getYears
.
import java.time.Period;
/*from w w w .j av a 2 s. c o 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.