public class demo {
public static void main(String[] args) throws ParseException {
Date date = new Date();
// System.out.println(date);
//Date --> String
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yy年MM月dd日 HH:mm:ss");
String format = simpleDateFormat.format(date);
System.out.println(format);
//String -->Date
String s = "22-1-1 00:00:00";
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
Date newDate = simpleDateFormat1.parse(s);
System.out.println(newDate);
}
}
![](https://img2020.cnblogs.com/blog/1678956/202112/1678956-20211230191141942-471534575.png)