Postgresql seem to convert timestamp parameter of PreparedStatement
<p>Postgresql seem to convert timestamp parameter of PreparedStatement which I set using setTimestamp.</p>

<p><strong>[What I want to do]</strong></p>

<p>I want to query today's data. ( 2016-06-30 00:00:00 ~ 2016-06-30 23:59:59) </p>

<p><strong>But, when I got the result from DB, it was data for 2016-06-29 15:00:00 to 2016-06-30 14:59:59. ( 9 hours gap)</strong> </p>

<p>My local timezone : GMT+9 (KST)</p>

<p>DB timezone : UTC (GMT+0)   ( In table, UTC time is stored as update time. I checked that. )</p>

<p>So 9 hours gap as I guess. When I pass UTC timestamp parameter to postgresql, it subtracted 9 hours from my timestamp parameters. I wonder why postgresql did so, and how I prevent that. </p>

<pre><code>SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
sdf2.setTimeZone(TimeZone.getTimeZone("UTC"));
Timestamp startTime = Timestamp.valueOf(sdf.format(new Date(System.currentTimeMillis())));
Timestamp endTime = Timestamp.valueOf(sdf2.format(new Date(System.currentTimeMillis())));

PreparedStatement pstmt = conn.prepareStatement( 
 "SELECT * FROM some_table WHERE update_time BETWEEN ? AND ? "
);
pstmt.setTimestamp(1, startTime);
pstmt.setTimestamp(2, endTime);
ResultSet rs = pstmt.executeQuery();
</code></pre>

<p><strong>[Table structure]</strong></p>

<pre><code>CREATE TABLE some_table
(
mem_no      bigserial
,data   char(2)
,update_time    timestamp with time zone DEFAULT current_timestamp
,CONSTRAINT pk_some_table PRIMARY KEY (mem_no)
);
</code></pre>

<p><strong>[Something strange]</strong></p>

<p>Using debugging tool, I checked pstmt value. Strangely <code>+09:00:00</code> was added to my parameters.</p>

<p>pstmt => SELECT * FROM some_table WHERE update_time BETWEEN 2016-06-30 00:00:00 <code>+09:00:00</code> AND 2016-06-30 23:59:59 <code>+09:00:00</code></p>

<p>DB : postgresql 9.3</p>