1 /** 2 * 日期格式转字符串 3 * */ 4 public static String test01(){ 5 DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); 6 return sdf.format(new Date()); 7 } 8 9 /** 10 * 字符串转日期 11 * */ 12 public static Date test02() throws ParseException { 13 DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); 14 String s = "2020-09-11 10:19:08"; 15 return sdf.parse(s); 16 }