0
I am unable to identify a problem using Java Localdate with Mysql Date. When saving a date in my Mysql database it saves on the correct date, for example: 2019-05-24.
When doing a search using criteriaQuery, it finds the expected record on the date, but is returning me the day before. I thought it might be the way I’m displaying the date in my converter:
@FacesConverter("localDateFacesConverter")
public class LocalDateFacesConverter implements Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent component, String stringValue) {
if (null == stringValue || stringValue.isEmpty()) {
return null;
}
LocalDate localDate = null;
try {
localDate = LocalDateHelper.strToLocalDate(stringValue.trim(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
} catch (DateTimeParseException e) {
throw new ConverterException("O formato da data deve ser 2015/11/15");
}
return localDate;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object instant) {
if (null == instant) {
return "";
}
if (component instanceof javax.faces.component.html.HtmlOutputText) {
if (instant instanceof LocalDate) {
return LocalDateHelper.formataLocalDate((LocalDate) instant, DateTimeFormatter.ofPattern("dd/MM/yyyy"));
} else if (instant instanceof LocalDateTime) {
return LocalDateHelper.formataLocalDateTime((LocalDateTime) instant, DateTimeFormatter.ofPattern("dd/MM/yyyy"));
}
return LocalDateHelper.formataInstant((Instant) instant, DateTimeFormatter.ofPattern("dd/MM/yyyy"));
}
if (instant instanceof LocalDate) {
return LocalDateHelper.formataLocalDate((LocalDate) instant, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
} else if (instant instanceof LocalDateTime) {
return LocalDateHelper.formataLocalDateTime((LocalDateTime) instant, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
}
return LocalDateHelper.formataInstant((Instant) instant, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
}
}
I’ve tried everything, but I can’t seem to solve the problem. Someone’s been there and they have a solution?
Probably a time zone problem.
– anonimo
@anonimo Because I also thought it would be, but it’s not, all configured for the correct time zone, at all times, in the bank, in the application server and in the code.
– Gilvan André
@anonimo I kept looking for a possible problem with the time zone and found. Thanks for the help!
– Gilvan André