Answer the question
In order to leave comments, you need to log in
Why does LocalDateTime write the date to the database incorrectly, with a shift of 11 hours ago?
Greetings dear forum users.
I can not understand what is happening with LocalDateTime.
1. Current time 2020-10-02 05:02:00 I
write the current date to the database.
2020-10-01 18:02:00
LocalDateTime.now()
On the next line I check the current date
2020-10-02T05:02:00
System.out.println(LocalDateTime.now());
Below on the line I check the current time zone of the server
2020-10-02T05:02:00+11:00[Asia/Sakhalin ]
System.out.println(ZonedDateTime.now());
Then I check the current time of the mysql server
mysql> SELECT CURTIME();
+-----------+
| CURTIME() |
+-----------+
| 05:02:00 |
+-----------+
SELECT EXTRACT(HOUR FROM (TIMEDIFF(NOW(), UTC_TIMESTAMP))) AS `timezone`;
+----------+
| timezone |
+----------+
| 11 |
+----------+
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question