2

My C++ program sets a timezone using method SetTimeZoneInformation() with values:

  • StandardName = "Central Europe Standard Time"
  • DaylightName = "Central Europe Daylight Time"
  • Bias = -60

It can then be easily read by C++ method GetTimeZoneInformation(). Demo can be found here:

But if I try to read this information by Java using this code:

TimeZone timeZone = Calendar.getInstance().getTimeZone();

... it shows a different value:

  • timeZone.getID() returns "GMT"
  • timeZone.getDisplayName() returns "Greenwich Mean Time"

It seems that both methods work with different data or they interpret it differently.

The same situation occurs when I change the timezone manually using windows-ui. Even if I select timezone "Hawaii" in Windows, Java still returns "GMT", while C++ retuns correct value "Hawaiian Standard Time". List of these textual IDs can be found here.

Do you have some experiences with both languages, please? Where does C++ write the info and where does it Java read from? Can I somehow propagate the timezone from Win to Java and visa versa?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Racky
  • 1,173
  • 18
  • 24
  • Java default timezone: http://stackoverflow.com/questions/2493749/how-to-set-a-jvm-timezone-properly. – mm759 Sep 15 '16 at 06:36
  • Thanks, now I wanted to paste the same link, but it does not solve my situation. I cannot pass parameters to my Java program during startup, I need to dynamically change the timezone in C++ or Java and use it immediately in the other environment. – Racky Sep 15 '16 at 06:42
  • Another link to similar topis is here. It says that there is some bug in Java: http://stackoverflow.com/questions/2106525/java-incorrect-timezone – Racky Sep 15 '16 at 06:46
  • In case Java's standard library has a bug, you can look for (or write) a library yourself that at least retrieves the correct timezone so you can set it programmatically in Java. – Banex Sep 15 '16 at 09:34
  • So I found out that it may work, but our Java had a problem when current timezone was using "Daylight saving time" (summer time). If it was used in the current timezone, Java returned GMT instead. – Racky Oct 10 '16 at 14:57

0 Answers0