Java - Write code to parse string in 2018-10-18 to Date

Requirements

Write code to parse string in 2018-10-18 to Date

Demo

//package com.book2s;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.ParseException;

public class Main {
    public static void main(String[] argv) {
        String date = "2018-10-18";
        System.out.println(stringConvertDate(date));
    }//from   w  w  w .  j  a va 2s  .  c o  m

    public static Date stringConvertDate(String date) {
        // TODO Auto-generated method stub
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date d = null;
        try {
            d = format.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return d;
    }
}

Related Exercise