0

I am using intellij for a javaee project and I get problems with time storage : there is a shift of 2 hours between what I put and the hour really stored in mysql.

some searches on internet gave nothing at the moment.

here is the java statement in which I set the hour of 15:30

Bien bien = new Bien(0, "mon super bien #2", 320, 5, 3, true,
                520000, "4 impasse des bleuets",
                LocalDateTime.of(2019, Month.MAY,1,15,30),
                false, bien0.getTypeChauffage(), bien0.getOptions(), bien0.getVille());

enter image description here

and you can see on the picture at the right that the stored hour is 13:30!! 2 hours were lost.

some informations :

I live in France, which is UTC+2 on summer hour; so I put this line in mysql' my.ini:

default-time-zone='+02:00'

and in phpmyadmin, if I type

select now();

I get the correct hour.

The wrong time is got from both intellij and phpmyadmin. The wrong time was got even before changing the default-time-zone in mysql.(but when I changed the timezone the previously entered datetime were shifted). the conection string is very usual,without any extra parameter(only database, port,user,password).

I will continue to search, but if someone can help me it would be kind.

here is an output from phpMyAdmin: enter image description here

lolveley
  • 1,659
  • 2
  • 18
  • 34

1 Answers1

1

The timezone in the database is always stored in UTC. I suppose you did not change the timezone in your phpmyadmin or intellj configuration, so you get to see the raw data.

If you haven't found this yet, check How do I set the time zone of MySQL?.

second
  • 4,069
  • 2
  • 9
  • 24
  • I actually changed phpmyadmin timezone, you can find the output in my edit. concerning intellij, I changed some values here and there (in the database connection, in the VM options) – lolveley May 18 '19 at 22:20
  • @lolveley Can you post the actual sql query that is fired when you try to insert it? What datatype do you use to store the date? – second May 18 '19 at 23:05
  • ok, the hour is stored in UTC, and read it from java give the correct hour : it is converted automatically. I was obsessed by the hour stored in the database, yet the correct hour is given by java. thank you. – lolveley May 19 '19 at 08:59