本文介绍了如何从“带时区的时间戳"列中读取时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到在带有时区的 timestamp 类型的PostgreSQL列中读取时区值的方法.

I am unable to find a way to read timezone value in PostgreSQL column of type timestamp with time zone.

JDBC提供方法 java.sql.ResultSet#getTimestamp(int,java.util.Calendar)但我必须提供自己的日历.我无法从正在读取的时间戳字段中获取该日历.

JDBC offers method java.sql.ResultSet#getTimestamp(int, java.util.Calendar)but I must provide my own calendar. I have see no way to obtain that calendar from timestamp field I am reading.

我正在研究存储多个时区的时间数据的系统.我需要保存带有时区信息的数据,并能够从数据库中读取该时区.

I am working on system that stores time data of multiple timezones. I need to save data with timezone information, and be able to read that timezone back from database.

有没有像这样的黑客攻击是否可能

Is it possible without hacks like

  • 在另一个字段中存储时区值
  • 将日期存储为字符串,例如"1997年Wed 17 Dec 07:37:16 PST"

我正在使用JDBC 41(JDBC4 Postgresql驱动程序,版本9.4-1201),java 8.

I am using JDBC 41 (JDBC4 Postgresql Driver, Version 9.4-1201), java 8.

推荐答案

PostgreSQL文档在这里说:

The PostgreSQL documentation here says that:

因此,无需存储时区(对应于时间戳值)" 本身;具有时区的时间戳值始终存储为UTC.

So there is no need to "store the time zone [that corresponds to the timestamp value]" per se; the timestamp with time zone values are always stored as UTC.

此外,也无需从时间戳字段获取日历".日历的目的是让您定义在Java应用程序中要使用的特定时区.

Also, there is no need to "obtain the Calendar from the timestamp field". The purpose of the Calendar is for you to define the particular timezone that you want to work with in your Java application.

换句话说,带时区的 timestamp 不会存储来自各个时区的值(例如,某些时区在EST中,其他时区在PST中,等等),当插入时间戳值时,它将所有内容转换为UTC

In other words, timestamp with timezone does not store values from various timezones (e.g., some in EST, others in PST, etc.), it converts everything to UTC when the timestamp values are inserted.

这篇关于如何从“带时区的时间戳"列中读取时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 17:29