原始方案:SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DD"); //线程不安全类,最好不要用了,
替代方案: DateTimeFormatter dtf = DateTimeFormatter.ofPattern("YYYY-MM-DD");
方案一:
String date_str = "2023-01-01";
Date date = null;
SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DD");
date = sdf.parse(date_str)
方案二:
String date_str = "2023-01-01";
LocalDate date = null;
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("YYYY-MM-DD");
date = LocalDate.parse(date_str);
标签:01,Java,处理,DD,SimpleDateFormat,YYYY,日期,DateTimeFormatter,date From: https://www.cnblogs.com/smarttony/p/17095872.html