我正在尝试将日期字段保存到mysql表中。 我的jsp表单中的日期字段格式为MM / DD / YYY,数据库格式为YYYY / MM / DD。 如何从表单中检索日期并以YYYY / MM / DD格式插入表格?
答案 0 :(得分:0)
String publishdt = request.getParameter("publish");
if(publishdt == null)
{
publishdt = "";
}
else
{
try
{
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
LocalDate date = LocalDate.parse(publishdt, formatter);
publish = String.format("%s", date);
}
catch (DateTimeParseException exc)
{
out.println("%s is not parsable!%n"+publish);
throw exc; // Rethrow the exception.
}
// 'date' has been successfully parsed
}