Java reporting wrong time zone in Jail

csab6597

Cadet
Joined
Apr 13, 2022
Messages
7
In TrueNAS-13.0-U6.1 in a jail I installed java, but now I get the wrong clock time in java. Observe the following:

Code:
# date
Sat Feb 10 10:36:35 CET 2024

So this shows I am in central europe timezone, which is correctly set up. But now just using jshell I get
Code:
# java -version
openjdk version "19.0.2" 2023-01-17
OpenJDK Runtime Environment (build 19.0.2+7-1)
OpenJDK 64-Bit Server VM (build 19.0.2+7-1, mixed mode, sharing)

# jshell
|  Welcome to JShell -- Version 19.0.2
|  For an introduction type: /help intro

jshell> java.time.ZonedDateTime.now()
$3 ==> 2024-02-10T09:38:12.192401862Z[GMT]

jshell> java.time.LocalDateTime.now()
$1 ==> 2024-02-10T09:38:12.192401862Z


So Java does not honor the time zone in TrueNAS and shows GMT and therefore the time is offset??
How to get corret clock time in Java in TrueNAS?
 
Last edited:

subnetspider

Dabbler
Joined
Aug 27, 2023
Messages
16
GMT and CET have an offset of one hour, so AFAIK this is expected behavior.
What time zone do you have set in TrueNAS under "System > General > Timezone"?
 

csab6597

Cadet
Joined
Apr 13, 2022
Messages
7
Sure there is an offset. I did set CET in the timezone.

I stated this is the correct output in the jail using the date command. Again, the date command proves the correct time is set in the jail. But java reports the wrong time and hence does not honor the timezone setting, which I have not heard of happening on other systems.
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
Could you try to
Code:
export TZ="Europe/Berlin"


and then run your java program? Possibly java doesn't get the system timezone automatically.
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
But java reports the wrong time and hence does not honor the timezone setting,
What you've shown is that Java reports the correct time, but not in the expected time zone. How to fix that? No clue; suggest you check the Java documentation.
 

csab6597

Cadet
Joined
Apr 13, 2022
Messages
7
Indeed the problem seems to be somewhere between TrueNAS and Java, such that Java does not get the timezone. I edited my initial post in that the more obvious LocalTime and LocalDateTime functions do not honor timezone settings besides the ZonedDateTime function.

I tested on two Linux Systems where indeed Java reports the correct time so I believe the problem rather on the TrueNAS side of things?
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
Not TrueNAS but FreeBSD. Go contact the FreeBSD java team and ask them if that's expected behaviour.

 

Ericloewe

Server Wrangler
Moderator
Joined
Feb 15, 2014
Messages
20,194
Aren't jails supposed to have independent timezones, that being a userland concept? If the jail is built from the standard template, it's probably going to use whatever the default is - and if someone is confusing UTC with GMT, well, there's the answer.

I really don't know much about timezone handling, my stuff is set to UTC, I live between UTC+0 and UTC+1, work with people mostly within UTC-1 and UTC+0. It's trivial much of the year, and easy the rest of the time.
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
Timezone is set by iocage and the default is to set it to the same value as the host. The manual "date" command in the shell clearly showed that the timezone in the jail is set to CET.
 

Ericloewe

Server Wrangler
Moderator
Joined
Feb 15, 2014
Messages
20,194
Missed that post, I read it as being run on the host. So I guess Java is ignoring the system's timezone, which does sound like a very Java thing to do.
 

csab6597

Cadet
Joined
Apr 13, 2022
Messages
7
I contacted the FreeBSD guys and we found the following:

When the appropriate FreeBSD command tzsetup xxx/yyy is used inside the Jail to set the timezone, then this will be reflected in the output of the date command as well as in any Java environment.
But when using the TrueNAS systemwide setting through System/General/Timezone then (after a Jail restart) that timzone change will be reflected in the date command only, but there is no change inside Java.

So for now I can live with the situation that timezone needs to be set up per Jail using the tzsetup function from FreeBSD. But I would appreciate if this was synchronized already.
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
That would be the job of iocage to do that. I'll look into what it actually does, because there is timezone related code in there to my knowledge.
 
Top