日期字符串 → java.sql.Date对象
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class StringToDateTest {
public static java.sql.Date changeStringToSQLDate(String dateString) {
SimpleDateFormat dateFormatHiddenHour = new SimpleDateFormat("yyyy-MM-dd");
java.sql.Date date = null;
try {
String s = dateFormatHiddenHour.format(dateFormatHiddenHour.parse(dateString));
date = java.sql.Date.valueOf(s);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
public static void main(String[] args) {
String endDate=" 2020-03-03";
System.out.println(changeStringToSQLDate(endDate));
}
}
来源:CSDN
作者:进阶的JFarmer
链接:https://blog.csdn.net/weixin_43896318/article/details/104639761