Re: Issue: Java does not honor timezone setting
Date: Wed, 14 Feb 2024 15:46:05 UTC
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> 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 >