Period plus() method in Java with Examples Last Updated : 27 Nov, 2018 Comments Improve Suggest changes Like Article Like Report The plus() method of Period class in Java is used to add the given amount of period to the specified period. This functions operates separately on YEAR, MONTH and DAY. Note: Normalization is not performed. 12 months and 1 year are different. Syntax: public Period plus(TemporalAmount amountToAdd) Parameters: This function accepts a single parameter amountToAdd, which is amount to add to period. It must not be null. Returns Value This function returns a Period based on the given period with the requested period added, and this must not be null. Exceptions: DateTimeException: This exception is returned if the specified amount has a non-ISO chronology or contains an invalid unit. ArithmeticException: This exception is caught if numeric overflow occurs. Below programs illustrate the above method: Program 1: Java // Java code to show the function plus() // to subtract the two given periods import java.time.Period; import java.time.temporal.ChronoUnit; public class PeriodDemo { // Function to subtract two given periods static void addPeriod(Period p1, Period p2) { System.out.println(p1.plus(p2)); } // Driver Code public static void main(String[] args) { // Defining first period int year = 4; int months = 11; int days = 10; Period p1 = Period.of(year, months, days); // Defining second period int year1 = 2; int months1 = 7; int days1 = 8; Period p2 = Period.of(year1, months1, days1); addPeriod(p1, p2); } } Output: P6Y18M18D Program 2: Period can be negative. Java // Java code to show the function plus() // to subtract the two given periods import java.time.Period; import java.time.temporal.ChronoUnit; public class PeriodDemo { // Function to add two given periods static void addPeriod(Period p1, Period p2) { System.out.println(p1.plus(p2)); } // Driver Code public static void main(String[] args) { // Defining second period int year1 = 2; int months1 = 7; int days1 = 8; Period p1 = Period.of(year1, months1, days1); // Defining first period int year = 4; int months = 11; int days = 10; Period p2 = Period.of(year, months, days); addPeriod(p1, p2); } } Output: P6Y18M18D Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Period.html#plus-java.time.temporal.TemporalAmount- Comment More infoAdvertise with us Next Article Period plus() method in Java with Examples B barykrg Follow Improve Article Tags : Misc Java Java-Functions Java-time package Java-Period +1 More Practice Tags : JavaMisc Similar Reads Period plusDays() method in Java with Examples The plusDays() method of Period class in Java is used to add the days to this period. This method operates only on DAYS and does not affect other two YEAR, MONTH. Syntax: public Period plusDays(long daysToAdd) Parameters: This method accepts a single parameter daysToAdd which is the number of days t 2 min read Period plusYears() method in Java with Examples The plusYears() method of Period class in Java is used to add the given years to this period. This functions operates only on YEARS and does not affect MONTH and DAYS. Syntax: public Period plusYears(long yearsToAdd) Parameters: This method accepts a single parameter yearsToAdd which is the number o 2 min read Period plusMonths() method in Java with Examples The plusMonths() method of Period class in Java is used to add the specified months to this current period. This functions operates only on MONTHS and does not affect YEARS and DAYS. Syntax: public Period plusMonths(long monthsToAdd) Parameters: This method accepts a single parameter monthsToAdd whi 2 min read Period of() method in Java with Examples The of() method of Period Class is used to obtain a period from given number of Years, Months, and Days as parameters. These parameters are accepted in the form of integers. This method returns a Period with the given number of years, months, and days. Syntax: public static Period of( int numberOfYe 2 min read Period get() method in Java with Examples The get() method of Period class in Java is used to get the value of the requested unit(YEARS, MONTHS or DAYS) given in the argument from this Period. Syntax: public long get(TemporalUnit unit) Parameters: This method accepts a single parameter unit of type TemporalUnit which is the unit to get requ 2 min read Like