-
How to convert a String to a Date object?
-
- SimpleDateFormat simple = new SimpleDateFormat(“yyyy-mm-dd”);
new Date().format(); - SimpleDateFormat simple = new SimpleDateFormat(“yyyy-mm-dd”);
simple.format(new Date()); - SimpleDateFormat simple = new SimpleDateFormat(“yyyy-mm-dd”);
new Date().parse(); - SimpleDateFormat simple = new SimpleDateFormat(“yyyy-mm-dd”);
simple.parse(new Date()); - None of these
- SimpleDateFormat simple = new SimpleDateFormat(“yyyy-mm-dd”);
Correct Option: D
SimpleDateFormat takes a string containing pattern. sdf.parse converts the String to Date object.