I have an issue with inserting datatime from the form input into the database. Specifically, I managed to parse data, but not the time.
I have database with DATETIME column 'timeFinished'.
I have JSP input:
<input type="datetime-local" path="timeFinished" name="timeFinished" id="timeFinished"/>
I have controller with InitBinder:
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sdf.setLenient(true);
binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
}
In this configuration the date is successfully being parsed to database like this:
1989-12-31 22:00:00
I don't know where is he getting 22:00:00, but it is like this. But I need to parse the time too. And it is not working when I add time to pattern:
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm");
sdf.setLenient(true);
binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
}
}
In this case the datetime value become NULL and nothing is being parsed to database at all. No errors are being showed.
How I can manage to parse both date and time into database? I've tried all possibilities for patterns - hh:mm:ss, HH:MM, HH:MM:SS and others. If I add time - it is not working. It works if I put date only.
Thank you in advance for your help.