JAVA日期字符串相互转换
public static void main(String[] args) { //1.日期转字符串 Date date = new Date(); String strDateFormat = "yyyy-MM-dd HH:mm:ss"; SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); System.err.println(sdf.format(date)); //2.字符串转日期 try { Date dateDate = sdf.parse("2021-03-30 10:17:04"); System.err.println(dateDate); } catch (ParseException e) { e.printStackTrace(); } }