-1

For some reason date fields of records get saved with the wrong hour in the database, in this case they go back by 2 hours. My application runs on tomcat 9. When running the app in my local machine using embedded tomcat this behavior doesn't replicate, while when it runs on the remote server it does. I have ruled out problems with the machine's time and Window's and the only variable in this case is tomcat but I can't find anything that can cause this behavior.

Here's a log4j entry displaying the correct log entry time but the wrong operation time:

2021-09-29 10:25:04,391 INFO ? [https-openssl-nio-8444-exec-8] ***.***.***.*** accessed resource /app/contracts/249 @ 29/09/2021 at 08:25:04

LOG ENTRY: 10:25

OPERATION: 08:25

cheroz
  • 117
  • 7
  • 5
    You have different timezone maybe UTC and UTC+2 – JEY Sep 29 '21 at 09:01
  • I have already ruled out a time zone difference. The machine's timezone and also Window's is correctly set. – cheroz Sep 29 '21 at 09:04
  • 1
    Come on. This is obviously a time zone issue. You are living in the central european time zone, which has UTC+2 in the summer, as it is now. – Seelenvirtuose Sep 29 '21 at 09:21
  • 2
    Is there a databose involved? Databases can have different time zones .. – Thilo Schwarz Sep 29 '21 at 09:56
  • Does this answer your question? [Daylight saving time and time zone best practices](https://stackoverflow.com/questions/2532729/daylight-saving-time-and-time-zone-best-practices) – Olaf Kock Sep 29 '21 at 12:25

1 Answers1

1

you need to explicitly set databases timezone to match the one on your machine for example in case of mysql jdbc:mysql://localhost:3306/DATABASE_NAME?serverTimezone=UTC

or in your case if it is UTC+2:

jdbc:mysql://localhost:3306/DATABASE_NAME?serverTimezone=Europe/Berlin

J Asgarov
  • 2,526
  • 1
  • 8
  • 18