Mysql date issue in different time zones

I have come across this date for a long time. I tried a lot of things, but in vain. The problem is as follows:

The date entered by the user is "2009-08-12". It is stored correctly in db.

In the GMT + 530 time zone, the date is also displayed correctly. But when I change the time zone to GMT + 1, the date becomes displayed as "2009-08-11", that is, it displays the date as 1 day ago.

Any help or input or suggestions would be very helpful.

thanks

Nait

+3
source share
4 answers

The date is probably stored as DATETIMEor TIMESTAMP,2009-08-12 00:00:00 +0530

Being converted to GMT+1, it gives you2009-08-11 19:30:00 +0100

MySQL DATETIME , , DATETIME, , , , .

MySQL TIMESTAMP UTC, .

+5

. , Martin Fowler.

, Java /, , - , .

, , . "2009-08-01 18:00" . , ; , .

. Java ( ), /. , Java ADD , Date. JDBC, Date. , / .

- , Java "" .

+3

@Quassnoi , , - java.sql.PreparedStatement java.sql.ResultSet, - , java.sql.PreparedStatement.setDate(int, Date, Calendar), java.sql.ResultSet.getDate(int, Calendar) ..

, , , UTC, , , .

, , , , , , .

+1

I had a similar problem with quartz using cron expressions, scheduled tasks were saved with the wrong hour value, I just set the server time zone where my application is located on my local time zone value, and the problem was fixed.

0
source

Source: https://habr.com/ru/post/1714963/


All Articles