0

I have a Java app with MySQL db. App and db run on server where is Timezone Europe/Prague. In connection url I use serverTimezone=CET.

In this case I have variable type Date (dd.MM.yyyy) and to db is save the day before.

But if I use serverTimezone=Europe/Prague this problem does not occur.

How is it possible? Where is a difference? Thanks

Deepak Rai
  • 2,163
  • 3
  • 21
  • 36
Martin Hofman
  • 53
  • 1
  • 6
  • 2
    You do not provide enough detail to make a good Answer. Two things to know: `CET` is not a time zone, `Europe/Prague` is. And, never use either `Date` class in Java. Supplanted years ago by the modern *java.time* classes. All this has been covered many many times on Stack Overflow. Search thoroughly before posting. – Basil Bourque Jan 25 '21 at 07:42
  • Seconding what @BasilBourque has said and also adding `serverTimezone=Europe/Prague` in the connection string is making a difference because your MySQL has been installed with a different timezone. – Arvind Kumar Avinash Jan 25 '21 at 07:46
  • 1
    Sorry, but it is old application on Java 1.8. And now I get my answer here: https://stackoverflow.com/questions/2934258/how-do-i-get-the-current-time-zone-of-mysql , Thanks – Martin Hofman Jan 25 '21 at 08:00

1 Answers1

1

According to the MySQL Server Time Zone Support, MySQL has a table that maps from (known) timezone names to timezones. Depending on the OS, this table may be populated from the OS's timezone database ... or from some other source.

So the reason for "Europe/Prague" working and "CET" not working is most likely that the OS's timezone database doesn't recognize "CET" as a timezone name.

Note that the 3 (or 4) letter time zone names are often ambiguous and it is best to avoid using them. For example CST can mean "China Standard Time", "Cuba Standard Time" or "Central Standard Time" ... which are 3 different zones.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216