E
E
Evgeny Krasnov2020-10-01 21:57:51
Java
Evgeny Krasnov, 2020-10-01 21:57:51

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  |
+-----------+


Next, I check the MySql timezone
SELECT EXTRACT(HOUR FROM (TIMEDIFF(NOW(), UTC_TIMESTAMP))) AS `timezone`;
+----------+
| timezone |
+----------+
|       11 |
+----------+


Everywhere all the dates and time zones are in order, but when I write data to the database , the date shifts 11 hours ago, that is, I write the current date 2020-10-02 05:02:00 and it gets into the database 2020-10-01 18 :02:00

What's happening and why is not clear.

Who can explain what's going on?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2020-10-01
@dimonchik2013

it writes it right
, but your knowledge is still
not enough to quickly jump into the enterprise salary, delve into
https://habr.com/ru/post/274905/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question