How to convert String into Date in one line in Java

Views: 282 Ask New Question


On By

1 Answer


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

On By


Answer This Question