AW: Issue: Java does not honor timezone setting

From: <csab6597_at_gmail.com>
Date: Wed, 14 Feb 2024 21:04:32 UTC
Hi Michael,

 

I used tzsetup and selected Europe/Austria. After doing so I now get the correct time zone and therefore time value in java.

 

# date

Wed Feb 14 21:21:06 CET 2024

 

# jshell

|  Welcome to JShell – Version 19.0.2

|  For an introduction type: /help intro

 

jshell> java.time.ZonedDateTime.now()

&1 ==> 2024-02-14T21_21_36.093531195+01:00[Europe/Vienna]

 

Now the situation is like

*	When I change the TrueNAS systemwide timezone, which was always set to Europe/Vienna by the way, that is indeed reflected through the “date” command (but only after a system restart). But such a change is not adopted in Java.
*	Whereas the other way round, any change through tzsetup is indeed reflected in Java as well as in “date”

 

At first I put up the following thread in the TrueNAS forum  <https://www.truenas.com/community/threads/java-reporting-wrong-time-zone-in-jail.116366/> https://www.truenas.com/community/threads/java-reporting-wrong-time-zone-in-jail.116366/ from where I was pointed to you. Do you think I should now point back to some TrueNAS configuration issue?

 

Greets, Rainer

 

 

 

Von: Michael Zhilin <mizhka@gmail.com> 
Gesendet: Mittwoch, 14. Februar 2024 16:46
An: csab6597@gmail.com
Cc: freebsd-java@freebsd.org
Betreff: Re: Issue: Java does not honor timezone setting

 

Hi,

 

I've tried to use /usr/share/zoneinfo/CET as /etc/localtime and it seems java can't identify TZ correctly.

But in case of particular country's TZ, it works fine:

 

 # tzsetup
root@tamagawa /usr/share/zoneinfo
 # date
Wed Feb 14 16:40:48 CET 2024
root@tamagawa /usr/share/zoneinfo
 # export JAVA_VERSION=17
root@tamagawa /usr/share/zoneinfo
 # jshell
|  Welcome to JShell -- Version 17.0.9
|  For an introduction type: /help intro

jshell> java.time.ZonedDateTime.now()
$1 ==> 2024-02-14T16:41:13.106408203+01:00[Europe/Andorra]

 

I have no access to TrueNAS & jdk19, could you please try to specify the country's TZ by tzsetup and check tz in java?

 

Thanks!

 

 

On Sun, Feb 11, 2024 at 12:53 AM <csab6597@gmail.com <mailto:csab6597@gmail.com> > wrote:

Hi there,

 

I am using TrueNAS Core TrueNAS-13.0-U6.1 where in a jail I installed jdk 19. In the shell I get

 

# 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)

 

The issue I encountered is that java does not honor the timezone I have set in TrueNAS.

When using the builtin command  in the TrueNAS shell I can see

 

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

 

So that command reports CET timezone which is in fact what it should be, what is set in TrueNAS system configuration

But inside java, for a test just using jshell, then java will report GMT which means java is ignoring the timezone setting and thus giving an offset to the actual time

 

# 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

 

 

Also tested in Windows and Ubuntu where Java will indeed report the correct timezone

 

Greets, Rainer