YearMonth parse(CharSequence) method in Java with Examples Last Updated : 27 Feb, 2019 Comments Improve Suggest changes Like Article Like Report The parse(CharSequence) method of YearMonth class used to get an instance of YearMonth from a string such as ‘2018-12’ passed as parameter.The string must have a valid value that can be converted to a YearMonth object. The format of String must be uuuu-MM. YearMonths outside the range 0000 to 9999 must be prefixed by the plus or minus symbol. Syntax: public static YearMonth parse(CharSequence text) Parameters: This method accepts only one parameter text which represents the text to parse and format of this String must be like uuuu-MM. Return value: This method returns the parsed YearMonth. Exception: This method throws following Exceptions: DateTimeException - if the text cannot be parsed. Below programs illustrate the parse(CharSequence text) method: Program 1: Java // Java program to demonstrate // YearMonth.parse(CharSequence text) method import java.time.*; public class GFG { public static void main(String[] args) { // create a YearMonth object // using parse(CharSequence text) YearMonth yearMonth = YearMonth.parse("2019-12"); // print instance System.out.println("YearMonth Parsed:" + yearMonth); } } Output: YearMonth Parsed:2019-12 Program 2: Java // Java program to demonstrate // YearMonth.parse(CharSequence text) method import java.time.*; public class GFG { public static void main(String[] args) { // create a YearMonth object // using parse(CharSequence text) YearMonth yearMonth = YearMonth.parse("2022-05"); // print instance System.out.println("YearMonth Parsed:" + yearMonth); } } Output: YearMonth Parsed:2022-05 References: https://docs.oracle.com/javase/10/docs/api/java/time/YearMonth.html#parse(java.lang.CharSequence) Comment More infoAdvertise with us Next Article YearMonth parse(CharSequence) method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java java-basics Java-Functions Java-YearMonth Practice Tags : Java Similar Reads Year parse(CharSequence) method in Java with Examples The parse(CharSequence) method of Year class is used to get an instance of Year from a string such as â2018â passed as parameter. The string must have a valid value that can be converted to a Year. Years outside the range 0000 to 9999 must be prefixed by the plus or minus symbol. Syntax: public stat 2 min read YearMonth parse(CharSequence,DateTimeFormatter) method in Java with Examples The YearMonth.parse(CharSequence, DateTimeFormatter) method of YearMonth class used to get an instance of YearMonth from a string such as â2018â passed as a parameter using a specificDateTimeFormatter.The YearMonth is parsed using a specific DateTimeFormatter. The string must have a valid value that 2 min read MonthDay parse(CharSequence) method in Java with Examples The parse(CharSequence text) method of the MonthDay class in Java is used to get an instance of MonthDay from a text string. Syntax: public static MonthDay parse( CharSequence text) Parameters: This method accepts text as parameter to parse. Return value: This method returns the parsed month-day. Ex 1 min read Duration parse(CharSequence) method in Java with Examples The parse(CharSequence) method of Duration Class in java.time package is used to get a Duration from a string passed as the parameter. The format for the String to be parsed is "PnDTnHnMn.nS" where "nD" means 'n' number of Days, "nH" means 'n' number of Hours, "nM" means 'n' number of Minutes, "nS" 2 min read Year parse(CharSequence,DateTimeFormatter) method in Java with Examples The Year.parse(CharSequence, DateTimeFormatter) method of Year class is used to get an instance of Year from a string such as â2018â passed as parameter using a specificDateTimeFormatter.The Year is parsed using a specific DateTimeFormatter. The string must have a valid value that can be converted t 2 min read YearMonth plusYears() method in Java with Examples The plusYears() method of YearMonth class in Java is used to return a copy of this YearMonth with the specified number of years added. Syntax: public YearMonth plusYears(long yearsToAdd) Parameter: This method accepts yearsToAdd as parameters which represents years to add to current YearMonth object 2 min read Pattern split(CharSequence) method in Java with Examples split(CharSequence) method of a Pattern class used to splits the given char sequence passed as parameter to method around matches of this pattern.This method can split charSequence into an array of String's, using the regular expression used to compile the pattern as a delimiter.so we can say that t 2 min read YearMonth range() method in Java with Examples range() method of the YearMonth class used to get the ValueRange object which is the range of field in terms of the minimum and maximum values for the field passed as a parameter. The method returns ValueRange object only for those fields which are supported by YearMonth object. So when the field is 2 min read YearMonth now(clock) method in Java with Examples now(Clock clock) method of the YearMonth class in Java is used to obtain the current year-month from the specified clock. Syntax: public static YearMonth now(Clock clock) Parameters: This method accepts clock as parameter which represents the clock to use. Return value: This method returns the curre 1 min read Pattern split(CharSequence,int) method in Java with Examples split(CharSequence, int) method of a Pattern class used to splits the given char sequence passed as parameter to method around matches of this pattern.The array returned contains each substring of the input sequence created by this method. The substrings in the array are in the order in which they o 3 min read Like