一、String类型的日期字符串转换为Date格式
PS:传过来的格式还可能有2023/01/01 等等,所以要指定只能传xxxx-xx-xx的格式,或者列一个格式集合做处理
String strTime = "2023-01-01"
// java.sql.Date
Date date = Date.valueOf(strTime);
二、将Date转换为String类型
Date date = new Date();
// 获得SimpleDateFormat类
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
String time=sf.format(date);
System.out.println("当前时间:"+time);//当前时间:2019-09-19