public static void main(String[] args) { String s = "2019-12-30 12:52:02"; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = null; try { date = format.parse(s); System.out.println("字符串格式时间转时间格式:"+date); } catch (ParseException e) { e.printStackTrace(); } String time = format.format(date.getTime()); System.out.println("格式化结果:" + time); }