Home » JAVA Programming » Basic Datatypes » Question
  1. How to convert a String to a Date object?
    1. SimpleDateFormat simple = new SimpleDateFormat(“yyyy-mm-dd”);
      new Date().format();
    2. SimpleDateFormat simple = new SimpleDateFormat(“yyyy-mm-dd”);
      simple.format(new Date());
    3. SimpleDateFormat simple = new SimpleDateFormat(“yyyy-mm-dd”);
      new Date().parse();
    4. SimpleDateFormat simple = new SimpleDateFormat(“yyyy-mm-dd”);
      simple.parse(new Date());
    5. None of these
Correct Option: D

SimpleDateFormat takes a string containing pattern. sdf.parse converts the String to Date object.



Your comments will be displayed only after manual approval.