java.time.Period.withDays() Method Example



Description

The java.time.Period.withDays(int days) method returns a copy of this Period with the specified days.

Declaration

Following is the declaration for java.time.Period.withDays(int days) method.

public Period withDays(int days)

Parameters

days − the days to represent, may be negative.

Return Value

a Period based on this period with the requested days, not null.

Example

The following example shows the usage of java.time.Period.withDays(int days) method.

package com.tutorialspoint;

import java.time.Period;

public class PeriodDemo {
   public static void main(String[] args) {

      Period period = Period.ofDays(2);
      System.out.println(period.toString());  
      period = period.withDays(5);
      System.out.println(period.toString());  
   }
}

Let us compile and run the above program, this will produce the following result −

P2D
P5D
Advertisements