Date issue in spring boot data rest
Finally, I found a solution. After the @ILyaCyclone and @OleV.V. comments, I started to search about timezone, spring boot, and LocalDate
. Indeed the LocalDate
doesn't carry UTC information. However, when I fetch this data from the database, the JVM needs to make a conversion to make the SQL date
become the LocalDate
.
Therefore, the first thing I made was to check the database timezone:
SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP) as GMT_TIME_DIFF;
which returned:
+--------------------+---------------------+--------------------+
| @@GLOBAL.time_zone | @@session.time_zone | @@system_time_zone |
+--------------------+---------------------+--------------------+
| SYSTEM | SYSTEM | -02 |
+--------------------+---------------------+--------------------+
and:
SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP)
returning:
+--------------------------------+
| TIMEDIFF(NOW(), UTC_TIMESTAMP) |
+--------------------------------+
| -02:00:00 |
+--------------------------------+
All these SQL answers were ok. So, the problem was in the spring boot. What solved the problem was to set the UTC in the code. I found this hint here.
@PostConstruct
void started() {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
}
After that, all the dates started to work properly.
Is solved the problem. However, I have no clue about the issue regarding the date after and before 1986. If someone has some hint, please share with me.
Thank you guys who put some effort to help me. I really appreciate that.