Java - Write code to parse string like 2018-10-12 01:01:02 to Date Time

Requirements

Write code to parse string like 2018-10-12 01:01:02 to Date Time

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-12 01:01:02";
        System.out.println(stringConvertDateTime(date));
    }//from  w w w . j a va  2 s. c  om

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