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