Java SQL Date parse String like "2020-12-31 00:00:00"
import java.sql.Date; import java.text.ParseException; import java.text.SimpleDateFormat; public class Main { public static void main(String args[]) throws ParseException { String strDate = "2020-12-31 00:00:00"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss"); java.util.Date date = sdf.parse(strDate); java.sql.Date sqlDate = new Date(date.getTime()); System.out.println("String converted to java.sql.Date :" + sqlDate); }/*ww w. j ava 2s .c om*/ }