Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The OP answered this question to change the default timezone for a single instance of a running JVM, set the <code>user.timezone</code> system property:</p> <pre><code>java -Duser.timezone=GMT ... &lt;main-class&gt; </code></pre> <p>If you need to set specific time zones when retrieving Date/Time/Timestamp objects from a database <code>ResultSet</code>, use the second form of the <code>getXXX</code> methods that takes a <code>Calendar</code> object:</p> <pre><code>Calendar tzCal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); ResultSet rs = ...; while (rs.next()) { Date dateValue = rs.getDate("DateColumn", tzCal); // Other fields and calculations } </code></pre> <p>Or, setting the date in a PreparedStatement:</p> <pre><code>Calendar tzCal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); PreparedStatement ps = conn.createPreparedStatement("update ..."); ps.setDate("DateColumn", dateValue, tzCal); // Other assignments ps.executeUpdate(); </code></pre> <p>These will ensure that the value stored in the database is consistent when the database column does not keep timezone information.</p> <p>The <code>java.util.Date</code> and <code>java.sql.Date</code> classes store the actual time (milliseconds) in UTC. To format these on output to another timezone, use <code>SimpleDateFormat</code>. You can also associate a timezone with the value using a Calendar object:</p> <pre><code>TimeZone tz = TimeZone.getTimeZone("&lt;local-time-zone&gt;"); //... Date dateValue = rs.getDate("DateColumn"); Calendar calValue = Calendar.getInstance(tz); calValue.setTime(dateValue); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload