Date: Wed, 14 Feb 2024 18:46:05 +0300 From: Michael Zhilin <mizhka@gmail.com> To: csab6597@gmail.com Cc: freebsd-java@freebsd.org Subject: Re: Issue: Java does not honor timezone setting Message-ID: <CAF19XBKqgFnGVHUq%2BZBOBqXwwrb0TTDKq5R_h_ayGtsXU=_Cfw@mail.gmail.com> In-Reply-To: <004901da5c6b$a36b1150$ea4133f0$@gmail.com> References: <004901da5c6b$a36b1150$ea4133f0$@gmail.com>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --] 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 > [-- Attachment #2 --] <div dir="ltr"><div>Hi,</div><div><br></div><div>I've tried to use /usr/share/zoneinfo/CET as /etc/localtime and it seems java can't identify TZ correctly.</div><div>But in case of particular country's TZ, it works fine:</div><div><br></div><div> # tzsetup<br>root@tamagawa /usr/share/zoneinfo<br> # date<br>Wed Feb 14 16:40:48 CET 2024<br>root@tamagawa /usr/share/zoneinfo<br> # export JAVA_VERSION=17<br>root@tamagawa /usr/share/zoneinfo<br> # jshell<br>| Welcome to JShell -- Version 17.0.9<br>| For an introduction type: /help intro<br><br>jshell> java.time.ZonedDateTime.now()<br>$1 ==> 2024-02-14T16:41:13.106408203+01:00[Europe/Andorra]</div><div><br></div><div>I have no access to TrueNAS & jdk19, could you please try to specify the country's TZ by tzsetup and check tz in java?</div><div><br></div><div>Thanks!<br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Feb 11, 2024 at 12:53 AM <<a href="mailto:csab6597@gmail.com">csab6597@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg-2397408257342209182"><div lang="DE-AT" style="overflow-wrap: break-word;"><div class="m_-2397408257342209182WordSection1"><p class="MsoNormal"><span lang="EN-US" style="font-size:11pt">Hi there,<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11pt"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11pt">I am using TrueNAS Core TrueNAS-13.0-U6.1 where in a jail I installed jdk 19. In the shell I get<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11pt"><u></u> <u></u></span></p><p class="MsoNormal" style="background:rgb(232,232,232)"><span lang="EN-US" style="font-size:10pt;font-family:"Courier New";color:black"># java -version</span><span lang="EN-US" style="font-size:10pt;font-family:"Courier New""><u></u><u></u></span></p><p class="MsoNormal" style="background:rgb(232,232,232)"><span lang="EN-US" style="font-size:10pt;font-family:"Courier New";color:black">openjdk version "19.0.2" 2023-01-17</span><span lang="EN-US" style="font-size:10pt;font-family:"Courier New""><u></u><u></u></span></p><p class="MsoNormal" style="background:rgb(232,232,232)"><span lang="EN-US" style="font-size:10pt;font-family:"Courier New";color:black">OpenJDK Runtime Environment (build 19.0.2+7-1)</span><span lang="EN-US" style="font-size:10pt;font-family:"Courier New""><u></u><u></u></span></p><p class="MsoNormal" style="background:rgb(232,232,232)"><span lang="EN-US" style="font-size:10pt;font-family:"Courier New";color:black">OpenJDK 64-Bit Server VM (build 19.0.2+7-1, mixed mode, sharing)</span><span lang="EN-US" style="font-size:10pt;font-family:"Courier New""><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11pt"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11pt">The issue I encountered is that java does not honor the timezone I have set in TrueNAS.<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11pt">When using the builtin command in the TrueNAS shell I can see<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11pt"><u></u> <u></u></span></p><pre style="background:rgb(232,232,232)"><span lang="EN-US" style="color:black"># date</span><span lang="EN-US"><u></u><u></u></span></pre><pre style="background:rgb(232,232,232)"><span lang="EN-US" style="color:black">Sat Feb 10 10:36:35 CET 2024</span><span lang="EN-US"><u></u><u></u></span></pre><p class="MsoNormal"><span lang="EN-US" style="font-size:11pt"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11pt">So that command reports CET timezone which is in fact what it should be, what is set in TrueNAS system configuration<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11pt">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<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11pt"><u></u> <u></u></span></p><pre style="background:rgb(232,232,232)"><span lang="EN-US" style="color:black"># jshell</span><span lang="EN-US"><u></u><u></u></span></pre><pre style="background:rgb(232,232,232)"><span lang="EN-US" style="color:black">| Welcome to JShell -- Version 19.0.2</span><span lang="EN-US"><u></u><u></u></span></pre><pre style="background:rgb(232,232,232)"><span lang="EN-US" style="color:black">| For an introduction type: /help intro</span><span lang="EN-US"><u></u><u></u></span></pre><pre style="background:rgb(232,232,232)"><span lang="EN-US"><u></u> <u></u></span></pre><pre style="background:rgb(232,232,232)"><span lang="EN-US" style="color:black">jshell> java.time.ZonedDateTime.now()</span><span lang="EN-US"><u></u><u></u></span></pre><pre style="background:rgb(232,232,232)"><span lang="EN-US" style="color:black">$3 ==> 2024-02-10T09:38:12.192401862Z[GMT]</span><span lang="EN-US"><u></u><u></u></span></pre><pre style="background:rgb(232,232,232)"><span lang="EN-US"><u></u> <u></u></span></pre><pre style="background:rgb(232,232,232)"><span lang="EN-US" style="color:black">jshell> java.time.LocalDateTime.now()</span><span lang="EN-US"><u></u><u></u></span></pre><pre style="background:rgb(232,232,232)"><span lang="EN-US" style="color:black">$1 ==> 2024-02-10T09:38:12.192401862Z</span><span lang="EN-US"><u></u><u></u></span></pre><p class="MsoNormal"><span lang="EN-US" style="font-size:11pt"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11pt"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11pt">Also tested in Windows and Ubuntu where Java will indeed report the correct timezone<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11pt"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11pt">Greets, Rainer <u></u><u></u></span></p></div></div></div></blockquote></div>help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAF19XBKqgFnGVHUq%2BZBOBqXwwrb0TTDKq5R_h_ayGtsXU=_Cfw>
