DateFormat parse(string , ParsePosition) Method in Java with Examples Last Updated : 24 Jan, 2022 Comments Improve Suggest changes Like Article Like Report DateFormat class of java.text package is an abstract class that is used to format and parse dates for any locale. It allows us to format date to text and parse text to date. DateFormat class provides many functionalities to obtain, format, parse default date/time. Note: DateFormat class extends Format class that means it is a subclass of Format class. Since DateFormat class is an abstract class, therefore, it can be used for date/time formatting subclasses, which format and parses dates or times in a language-independent manner. Package-view: java.text Package DateFormat Class parse(string , ParsePosition) Method The parse(String the_text, ParsePosition position) method of DateFormat class is used to parse the text from a string to produce the Date. The method parses the text starting at the index given by a start position. Syntax: public abstract Date parse(String the_text, ParsePosition position) Parameters: It takes 2 parameters: the_text: This is of the String type and refers to the string which is to be parsed to produce the date.position: This is of ParsePosition object type and refers to the information of the starting index of the parse. Return Type: Returns the Date parsed from the string or Null in case of an error. Example 1: Java // Java Program to Illustrate parse() Method // of DateFormat Class // Importing required classes import java.text.*; import java.util.Calendar; // Main class public class GFG { // Main driver method public static void main(String[] args) { // Creating object of DateFormat class inside main() DateFormat DFormat = new SimpleDateFormat("MM/ dd/ yy"); // Try block to check for exceptions try { Calendar cal = Calendar.getInstance(); // Parsing date From string // using parse() method of DateFormat class // Custom string date String dt = "10/ 27/ 16"; // Printing the above unparsed date System.out.println("The unparsed" + " string is: " + dt); // Parsing date using parse() method cal.setTime(DFormat.parse(dt)); // Printing the parsed time System.out.println("Time parsed: " + cal.getTime()); } // Catch block to handle exceptions catch (ParseException except) { // Display exceptions with line number // using printStackTrace() method except.printStackTrace(); } } } Output: The unparsed string is: 10/ 27/ 16 Time parsed: Thu Oct 27 00:00:00 UTC 2016 Example 2: Java // Java Program to Illustrate parse() Method // of DateFormat Class // Importing required classes import java.text.*; import java.util.Calendar; // Main class public class GFG { // Main driver method public static void main(String[] args) { // Creating an object of DateFormat class DateFormat DFormat = new SimpleDateFormat("MM/ dd/ yy"); // Try bloc kto check for exceptions try { // Getting instance from calendar Calendar cal = Calendar.getInstance(); // Parsing date from string // using parse() method String dt = "01/ 29/ 19"; // Displaying the unparsed date System.out.println("The unparsed" + " string is: " + dt); // Parsing date cal.setTime(DFormat.parse(dt)); System.out.println("Time parsed: " + cal.getTime()); } // Catch block to handle the exceptions catch (ParseException except) { // Display exception with line number // using printStackTrace() method except.printStackTrace(); } } } OutputThe unparsed string is: 01/ 29/ 19 Time parsed: Tue Jan 29 00:00:00 UTC 2019 Comment More infoAdvertise with us Next Article DateFormat parse(string , ParsePosition) Method in Java with Examples chinmoy lenka Follow Improve Article Tags : Misc Java Java-Functions Java-text package Java-DateFormat +1 More Practice Tags : JavaMisc Similar Reads ParsePosition toString() method in Java with Example The toString() method of java.text.ParsePosition class is used to retrieve the parse position object represented in the form of string.Syntax: public String toString() Parameter: This method does not accepts any argument as parameter.Return Value: This method returns the parse position object repres 2 min read Date toString() method in Java with Examples The toString() method of Java Date class converts this date object into a String in form "dow mon dd hh:mm:ss zzz yyy". This method overrides toString in class object. Syntax: public String toString() Parameters: The function does not accept any parameter. Return Value: It method returns a string re 2 min read ChoiceFormat parse() method in Java with Examples The parse() method of java.text.ChoiceFormat class is used to get the limit value for particular format in ChoiceFormat object. Syntax: public Number parse(String text, ParsePosition status) Parameter: This method takes the following parameters: text: which is the text for which limit value have to 2 min read 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. Syntax: public static Period parse(CharSequence text) Parameters: This method accepts a single parameter text which is the String to b 2 min read ChronoLocalDate toString() method in Java with Examples The toString() method of a ChronoLocalDate interface is used to get this date as a String, such as 2019-01-01.The output will be in the ISO-8601 format uuuu-MM-dd. Syntax: public String toString() Parameters: This method does not accepts any parameters. Return value: This method returns String which 1 min read ParsePosition getIndex() method in Java with Example The getIndex() method of java.text.ParsePosition class is used to retrieve the current parse position of this ParsePositon object . Syntax: public int getIndex() Parameter: This method does not accepts any argument as parameter. Return Value: This method returns the current parse position of this pa 2 min read DateFormat format() Method in Java with Examples DateFormat class present inside java.text package is an abstract class that is used to format and parse dates for any locale. It allows us to format date to text and parse text to date. DateFormat class provides many functionalities to obtain, format, parse default date/time. DateFormat class extend 2 min read OffsetTime atDate() method in Java with examples The atDate() method of OffsetTime class in Java combines this time with a date to create a OffsetDateTime. Syntax : public OffsetDateTime atDate(LocalDate date) Parameter: This method accepts a single parameter date which specifies the date to combine with, not null. Return Value: It returns the Off 2 min read MonthDay toString() Method in Java with Examples toString() method of the MonthDay class used to represents this month-day as a String like --08-23.The output will be in the format --MM-dd:Syntax: public String toString() Parameters: This method did not accepts any parameter.Return value: This method returns a String representation of this MonthDa 1 min read OffsetTime toString() method in Java with examples The toString() method of OffsetTime class in Java outputs this date as a String, such as "11:25:10+11:10" for an example. Syntax : public String toString() Parameter: This method does not accepts any parameter. Return Value: It returns a string representation of this date, not null. Below programs i 1 min read Like