How to convert String into Date in one line in Java


1 Answer

7 years ago by

You can use java.text.SimpleDateFormat Class to parse Date Strings in specified formats.
Following is the sample code

Date dateObject = new SimpleDateFormat("yyyy-MM-dd").parse("2017-10-15");

Note: This line will throw the java.text.ParseException if the String does not match with the pattern

7 years ago by Karthik Divi