As the tittle say I'm trying to retrieve a Date Time from HTML5 date time input and add it to my database here's the code
private void HandleDate(String date, Test test) {
DateTime dt = null;
try {
dt = CheckDateValidity(date);
} catch (TestManagementException e) {
setErrors(FIELD_DATE, e.getMessage());
}
test.setDate(dt);
}
private DateTime CheckDateValidity(String date) throws TestManagementException {
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-mm-dd hh:mm:ss");
DateTime dateTime;
try {
dateTime = formatter.parseDateTime(date);
} catch (Exception e) {
throw new TestManagementException("date couldn't be converted");
}
return dateTime;
}
everything seems good no errors detected but the database stayed the same no raw was added. what's wrong ? :/ another problem or a question: what's the pattern that i should use in the input so that the user should enter only this kind of date:
yyyy-mm-dd HH:mm:ss
ps:
when i tried doing this:
private void HandleDate(String date, Test test) {
DateTime dt = null;
try {
CheckDateValidity(date, dt);
} catch (TestManagementException e) {
setErrors(FIELD_DATE, e.getMessage());
}
test.setDate(dt);
}
private void CheckDateValidity(String date, DateTime dateTime) throws TestManagementException {
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-mm-dd hh:mm:ss");
// DateTime dateTime;
try {
dateTime = formatter.parseDateTime(date);
} catch (Exception e) {
throw new TestManagementException("date couldn't be converted");
}
// return dateTime;
}
it was added to the database but the date value was empty