Easy learning with example program codes

Java Period class

The java.time.Period class is used to measures time in years, months and days.

Java Period class methods

Method Description
Temporal addTo(Temporal temporal) It is used to add this period to the specified temporal object.
long get(TemporalUnit unit) It is used to get the value of the requested unit.
int getYears() It is used to get the amount of years of this period.
boolean isZero() It is used to check if all three units of this period are zero.
Period minus(TemporalAmount amountToSubtract) It is used to return a copy of this period with the specified period subtracted.
static Period of(int years, int months, int days) It is used to obtain a Period representing a number of years, months and days.
Period plus(TemporalAmount amountToAdd) It is used to return a copy of this period with the specified period added.


package com.codesjava;
import java.time.LocalDate;
import java.time.Period;
import java.time.temporal.Temporal;
public class TestExample {
	public static void main(String args[]){
	    Period period = Period.ofDays(24);  
	    Temporal temporal = period.addTo(;  
	    //plus() method
	    //minus() method


Posted in Date   

Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at


We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki