Java - Write code to parse String in yyyy-MM-dd format To Date

Requirements

Write code to parse String in yyyy-MM-dd format To Date

Demo

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main{
    public static void main(String[] argv){
        String time = "book2s.com";
        System.out.println(StringToDate(time));
    }/*from  ww w. j a v a2s. c  o m*/
    public static Date StringToDate(String time) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.parse(time);
    }
}