Java Date parse String like "2020-01-31 12:12:12" to date
import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static void main(String[] argv) { String sMt = "2020-01-31 12:12:12"; System.out.println(convertStringToDate(sMt)); }/*from w w w. ja va 2 s . com*/ public static Date convertStringToDate(String sMt) { try { java.util.Date utilDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(sMt); return utilDate; } catch (Exception e) { e.printStackTrace(); return null; } } }