Hello
In your case, the reason you are returning the date 1 day apart is that your database is configured with the UTC-3 date which is America/Sao_Paulo
, that you added to the database connection:
jdbc:mysql://localhost:3306/meubanco?createDatabaseIfNotExist=true&useSSL=false&serverTimezone=America/Sao_Paulo
Although your bank is with the UTC-3 that is correct, your application is not, and ends up taking the local UTC, which is UTC-3, but when redeeming the data it decreases the -3 hours which makes the date decrease 1 day, because, your application thinks that the date returned is in UTC format, then reduces -3 hours.
So the best solution is for the application and the database to be configured with the same zone, as Melchior Felix said, but instead of "UTC", "America/Sao_paulo".
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@PostConstruct
public void init() {
TimeZone.setDefault(TimeZone.getTimeZone("America/Sao_Paulo"));
}
}
It worked, thank you!
– Murylo Capucho