How does Hotspot JVM pinpoint the current timezone on Linux (Centos)?

I have a problem where the current timezone is not defined correctly in a JVM instance running inside a Docker container (both host and container are Cent OS 6.5).

First of all, I mapped etc/localtime

to the child container via -v /etc/localtime:/etc/localtime:ro

(I think this is the common way )

When I login via SSH on both host and container

date -u

seal Mon Apr 20 11:48:57 UTC 2015

and

date

seal Mon Apr 20 14:50:41 MSK 2015

However in the JVM

System.out.println (new date ());

I am getting Mon Apr 20 11:52:24 UTC 2015

inside the container and Mon Apr 20 14:53:17 MSK 2015

inside the host.

How exactly is the current time zone determined?

Oracle FAQ does not shed light, I do not quite understand what metrics Java uses Java to get the time zone for the current user

Does my operating system time zone patch set the Java platform to time zone information?

Not. Java SE platform time zone data is not read from the local or host operating system. The Java SE platform maintains a private repository of time zone data in locally installed files (... / jre / lib / zi) as part of the Java Runtime Environment (JRE) software. Applying any operating system time zone fixes (for example, Solaris, Linux, Windows) will not affect the accuracy of the Java SE platform time zone data.

update: if anyone is interested in a workaround - I have specified the TZ environment variable as in Steven's answer so now the container is created with parameters

-v / etc / localtime: / etc / localtime: ro -e "TZ = Europe / Moscow"

+3


source to share


1 answer


According to this page , a JVM running on Linux uses the TZ environment variable to give it a local timezone name.

It goes on to explain that TZ is usually set to "/ etc / profile" and does not work if Java is started using a mechanism that does not "send" this file.




The timezone data referenced by Oracle refers to something else. This is the data the JVM uses to map from time zone names to the corresponding zone offsets (including daylight saving time adjustments, etc.).

+2


source







All Articles