我有一个名为deadline_date
type timestamp with time zone
with value 的字段2018-05-03 19:00:00-05.
select deadline_date from invoice_details where file_name='BHDHSB.pdf';
deadline_date
------------------------
2018-05-03 19:00:00-05
(1 row)
但是在从我的 java 代码中查询时,它返回的值是2018-05-04 05:30:00+05:30
.
我认为它正在根据我当地的时区转换日期。
有没有办法获得存储在表中的值?
我正在为 Postgres 使用以下 maven 依赖项
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1212</version>
</dependency>
测试.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Test {
public static Connection connection;
public void createConnection()
{
try {
if (connection==null) {
Class.forName("org.postgresql.Driver");
connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/abc", "abc", "Welcome");
connection.setSchema("iiv_location");
}
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getClass().getName() + ": " + e.getMessage());
}
}
public static void main(String[] args) {
try {
test object = new test();
object.createConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("select iiv_prescan_invoice_details.deadline_date from iiv_prescan_invoice_details");
while (resultSet.next()) {
System.out.println(resultSet.getString("deadline_date"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}