Creates an instance of Period from the provided text string. The text must be of PnYnMnD format, where
nY = n number of years
nM = n number of months
nD = n number of days
Examples
package com.logicbig.example.period;
import java.time.Period;
public class ParseExample {
public static void main(String... args) { //pattern PnYnMnD parse("P2Y");//2 years parse("P2Y5M");//2 years 5 months parse("P2Y5M10D");//2 years 5 months 10 days parse("-P2Y5M10D"); parse("P-2Y-5M-10D"); parse("P2Y5M-10D"); }
private static void parse(String pattern) { Period p = Period.parse(pattern); System.out.printf("%15s > %s%n", pattern, p); } }