How to Convert String to Date?



Share on Google+Share on Google+

Java Coder
How to Convert String to Date?
1 Answer(s)      3 years and 8 months ago
Posted in : Java Beginners


I am new in Java and learning the Date manipulation in Java. I have to write a program in Java which converts the String into Date object. My user enters the date into input field and now I have to convert it to Date object.

Tell me How to Convert String to Date?


View Answers

January 4, 2014 at 10:24 PM

Hi Dude,

Its very easy to convert the String into date format. There is a class SimpleDateFormat which already available in the JDK which you can use for converting the String representation of date into real Date object.

You can use the following code:

  formatter = new SimpleDateFormat("dd-MMM-yy");
  date = (Date)formatter.parse(str_date);

The parse() method of the SimpleDateFormat class returns the date object.

Read more at Convert String to Date.



Related Tutorials/Questions & Answers: