Period parse() method in Java with Examples
The parse() method of Period Class is used to obtain a period from given string in the form of PnYnMnD where nY means n years, nM means n months and nD means n days.
public static Period parse(CharSequence text)
Parameters: This method accepts a single parameter text which is the String to be parsed.
Returns: This function returns the period which is the parsed representation of the String given as the parameter
Below is the implementation of Period.parse() method:
1 Years 2 Months 21 Days
-1 Years -2 Months -21 Days
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.