// 创建日期对象
Date date = new Date();
// 从 Date 到 String
SimpleDateFormat format1 = new SimpleDateFormat();
System.out.println(format1.format(date)); // 2021/7/21 下午5:09
SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(format2.format(date)); // 2021-07-21 17:09:14
// 从 String 到 Date (throws ParseException)
String time = "2021-07-21 17:09:14";
SimpleDateFormat format3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(format3.parse(time)); // Wed Jul 21 17:09:14 CST 2021