Is it possible to handle different date format in a Spring MVC controller?
I know that setting something like this
@InitBinder
protected void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
binder.registerCustomEditor(Date.class, new CustomDateEditor(
dateFormat, false));
}
I can handle dd/MM/yyyy format, but what if i want to parse also dates in yyyyMMddhhmmss format? Should I add multiple CustomDateEditors in my controller?
If at a time you receive only one format of date, then you could simply create one instance of
DateFormatbased on formatfor example
Decide the format based on the input