Oracle TIMESTAMP WITH TIMEZONE 命名区域与偏移量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/588286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 01:44:29  来源:igfitidea点击:

Oracle TIMESTAMP WITH TIMEZONE named zone vs offset

oracledatetimetimezonetimestampdst

提问by tobyc

In oracle, is the named timezone always stored?

在 oracle 中,是否始终存储命名时区?

I have been testing this column within our system, and in some places the timestamp is shown as:

我一直在我们的系统中测试此列,在某些地方时间戳显示为:

26-FEB-09 11.36.25.390713 AM +13:00

but other times it's:

但其他时候是:

26-FEB-09 11.36.25.390713 AM Pacific/Auckland

If the value is being stored as the former, does that mean the actual timezone is not being stored?

如果该值存储为前者,是否意味着未存储实际时区?

I worry because if a future date is stored with only an offset we might not be able to determine the actual time in the original timezone, because you can determine a offset from a timezone, but not vice versa.

我担心,因为如果未来的日期只存储一个偏移量,我们可能无法确定原始时区的实际时间,因为您可以确定时区的偏移量,但反之则不行。

Thanks

谢谢

采纳答案by tobyc

I've found that setting the TimeZone and format within ODP.NET when a connection is opened seems to solve this problem:

我发现在打开连接时在 ODP.NET 中设置 TimeZone 和格式似乎可以解决这个问题:

OracleGlobalization info = conn.GetSessionInfo();
info.TimeZone = "Pacific/Auckland";
info.TimeStampFormat = "DD-MON-YYYY HH:MI:SS.FF AM";
info.TimeStampTZFormat = "DD-MON-YYYY HH:MI:SS.FF AM TZR";
conn.SetSessionInfo(info);

回答by

It's pretty easy to test

很容易测试

 create table foo ( tswtz TIMESTAMP WITH TIME ZONE);
    /

insert into foo values (TO_TIMESTAMP_TZ ('21-FEB-2009 18:00:00 -5:00', 'DD-MON-YYYY HH24:MI:SS TZH:TZM'));


insert into foo values (TO_TIMESTAMP_TZ ('21-FEB-2009 18:00:00 EST', 'DD-MON-YYYY HH24:MI:SS TZR'));
    select tswtz, extract(timezone_abbr from tswtz), extract(TIMEZONE_REGION from tswtz)
from foo;


TSWTZ         EXTRACT(TIMEZONE_ABBRFROMTSWTZ) EXTRACT(TIMEZONE_REGIONFROMTSWTZ)                                
------------- ------------------------------- ---------------------------------------------------------------- 
21-FEB-09 06.00.00.000000000 PM -05:00   UNK                          UNKNOWN                                                          
21-FEB-09 06.00.00.000000000 PM EST      EST                             EST                                                              

2 rows selected

It stores what you tell it. If you tell it an offset, that offset could be good for one or more timezones, so why would it just pick one?

它存储您告诉它的内容。如果你告诉它一个偏移量,这个偏移量可能对一个或多个时区有好处,那么为什么它只选择一个呢?