Java Data Type How to - Create Period for 2 months and 5 days








Question

We would like to know how to create Period for 2 months and 5 days.

Answer

// w w w .ja v  a  2 s .c  om
import java.time.Period;

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

    Period twoMonthsAndFiveDays = Period.ofMonths(2).plusDays(5);

    System.out.println(twoMonthsAndFiveDays);
  }
}

The code above generates the following result.