JAVA时间格式String-Date互相转化
1、Date 转 String
Date date = new Date()
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
String thetime= sdf.format(date);
System.out.println(thetime);
2、String转 Date
String thetime="2020-11-18";
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
Date fucktime= sdf.parse(thetime);
System.out.println(fucktime);
其中 SimpleDateFormat sdf= new SimpleDateFormat(“yyyy-MM-dd”); 的 yyyy-MM-dd 可以换成 yyyy、yyyy-MM-dd HH:mm:ss等