title: Timezone problem when combining Tomcat9 with MySQL8
body: <p>I use the <code>time TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3);</code> for the time column so it will be automatically set when I insert a new line. </p>
  
  <p>According to <a href="https://dev.mysql.com/doc/refman/8.0/en/datetime.html" rel="nofollow noreferrer">MySQL TIMESTAMP Type Manual</a>, </p>
  
  <blockquote>
    <p>MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval. </p>
  </blockquote>
  
  <p>It seems fine when use SELECT() function in the CLI:</p>
  
  <pre><code>mysql&gt; SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP);
  +--------------------------------+
  | TIMEDIFF(NOW(), UTC_TIMESTAMP) |
  +--------------------------------+
  | 08:00:00                       |
  +--------------------------------+
  
  1 row in set (0.00 sec)
  
  mysql&gt; select time from databasename.tablename;
  +-------------------------+
  | time                    |
  +-------------------------+
  | 2018-12-16 22:02:45.891 |
  | 2018-12-16 22:02:46.032 |
  | 2018-12-16 22:02:46.169 |
  | 2018-12-16 22:02:46.304 |
  
  ```data following```
  </code></pre>
  
  <p>However when I try to display it in Tomcat based JSP page use:</p>
  
  <pre><code>&lt;td align="center"&gt;
  &lt;c:set var="time" value="${row.time}" /&gt;
  &lt;fmt:setTimeZone value="GMT+8" /&gt;
  &lt;fmt:formatDate value="${time}" pattern="yyyy-MM-dd HH:mm:ss.SSS" /&gt;
  &lt;/td&gt;
  </code></pre>
  
  <p>it displays a strange time which is 14 hours earlier then GMT+8, while printing the current time is normal:</p>
  
  <pre><code>&lt;td align="center" colspan="14"&gt;
  &lt;h1&gt;
  &lt;c:set var="now" value="&lt;%=new java.util.Date()%&gt;" /&gt;
  &lt;fmt:formatDate value="${now}" pattern="yyyy-MM-dd HH:mm" /&gt;
  &lt;/h1&gt;
  &lt;/td&gt;
  </code></pre>
  
  <p>Any ideas about what's going on?</p>
  
  <p>PS:
  the <code>row</code> is from the <a href="https://tomcat.apache.org/tomcat-9.0-doc/jndi-datasource-examples-howto.html#MySQL_DBCP_2_Example" rel="nofollow noreferrer">Official Tomcat Connect Tutorial</a>'s demo codes in <code>4. Test code</code> as below:</p>
  
  <pre><code>&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %&gt;
  &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;
  
  &lt;sql:query var="rs" dataSource="jdbc/TestDB"&gt;
  select id, foo, bar from testdata
  &lt;/sql:query&gt;
  
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;DB Test&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
  
    &lt;h2&gt;Results&lt;/h2&gt;
  
  &lt;c:forEach var="row" items="${rs.rows}"&gt;
      Foo ${row.foo}&lt;br/&gt;
      Bar ${row.bar}&lt;br/&gt;
  &lt;/c:forEach&gt;
  
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>