When i retrieve a date from a mysql table it always return the date 1 day before, the date format is yyyy-MM-dd, so if i have 2018-10-17 when i print the result it comes as 2018-10-16. If i use the command line to check the dates, they are correct. This is the method inside the Dao class that retrieves the dates:
public List<LocalDate> getDates(String username){
List<LocalDate> dates;
Query query = manager.createQuery("select date from Calendar where username =:username");
query.setParameter("username",username);
dates = query.getResultList();
return dates;
}
When I print the list all the dates are printed 1 day before as I was on my sql.
This is how I get the dates on the servlet and use hibernate to store the dates on mysql.
String dateString = request.getParameter("date");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate dataInicial = LocalDate.parse(dataInicialString, formatter);
The Datatype that im using in mysql is DATE. Then I user hibernate to do the rest for me, if you need any piece of code that I didin't provide please ask me. Thx in advance.
Sorry for bad english!
DateandSimpleDateFormatare outdated and poorly designed. A newer Hibernate should be able to get you the date asLocalDatefrom the database, which I warmly recommend. It solves your problem since aLocalDatehas got neither time of day nor time zone. As an extra bonusLocalDateand the other classes from java.time are so much nicer to work with. java,time is the modern Java date and time API.