我使用以下代码设置日期格式:
@InitBinder
public void initBinder(final WebDataBinder binder) {
binder.initDirectFieldAccess();
final SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
并从jsp以相同的格式发送日期,但出现错误:
Failed To Convert Property Value Of Type [Java.Lang.String] To Required Type [Java.Util.Date] For Property BidDate; Nested Exception Is Java.Lang.IllegalArgumentException: Could Not Parse Date: Unparseable Date: "05/28/2017"
最佳答案
您的日期格式为 dd/MM/yyyy
,但您向其传递了 MM/dd/yyyy
日期 (05/28/2017
)
关于java - 提交表单时出现 Spring 日期转换错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44230303/