The parse() Method of SimpleDateFormat 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.
public Date parse(String the_text, ParsePosition position)
Parameters: The method takes two 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 Value: The method either returns the Date parsed from the string or Null in case of an error.
Below programs illustrate the working of parse() Method of SimpleDateFormat:
The unparsed string is: 10/ 27/ 16 Time parsed: Thu Oct 27 00:00:00 UTC 2016
The unparsed string is: 01/ 29/ 19 Time parsed: Tue Jan 29 00:00:00 UTC 2019
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.