<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Scala on KK's Blog (fromkk)</title><link>https://fromkk.com/tags/scala/</link><description>Recent content in Scala on KK's Blog (fromkk)</description><generator>Hugo</generator><language>en</language><managingEditor>bebound@gmail.com (KK)</managingEditor><webMaster>bebound@gmail.com (KK)</webMaster><lastBuildDate>Sun, 10 Aug 2025 18:44:06 +0800</lastBuildDate><atom:link href="https://fromkk.com/tags/scala/index.xml" rel="self" type="application/rss+xml"/><item><title>Timezone in JVM</title><link>https://fromkk.com/posts/timezone-in-jvm/</link><pubDate>Sun, 18 Oct 2020 23:49:00 +0800</pubDate><author>bebound@gmail.com (KK)</author><guid>https://fromkk.com/posts/timezone-in-jvm/</guid><description>&lt;p&gt;I wrote a Scala code to get the current time. However, the output is different on the development server and docker.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-scala" data-lang="scala"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;import&lt;/span&gt; java.util.Calendar
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;println&lt;span style="color:#f92672"&gt;(&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;Calendar&lt;/span&gt;&lt;span style="color:#f92672"&gt;.&lt;/span&gt;getInstance&lt;span style="color:#f92672"&gt;().&lt;/span&gt;getTime&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;On my development server, it outputs &lt;code&gt;Sun Oct 18 18:01:01 CST 2020&lt;/code&gt;, but in docker, it print a UTC time.&lt;/p&gt;
&lt;p&gt;I guess it related to the timezone setting and do a research, here is the result.&lt;/p&gt;
&lt;h2 id="how-did-jvm-detect-timezone"&gt;How Did JVM Detect Timezone&lt;/h2&gt;
&lt;p&gt;All of the code can be found in this function: &lt;code&gt;private static synchronized TimeZone setDefaultZone()&lt;/code&gt;&lt;/p&gt;</description></item></channel></rss>