1.Date转String
Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateTime = sdf.format(date);
2.String 转Date
String dateTime = "2019-01-01 01:01:01"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { Date date = sdf.parse(dateTime); } catch (ParseException e) { e.printStackTrace(); }