oracle 中的时区偏移
使用 Oracle 9.2i,我需要获取一个时区的各种日期相对于另一个时区的偏移量,之前我是这样做的,
select
(TO_DATE('10-Oct-2010 09:00:00','DD-Mon-YYYY HH24:Mi:SS') -
TO_DATE(TO_CHAR(FROM_TZ(to_timestamp( '10-Oct-2010 09:00:00','DD-Mon-YYYY HH24:Mi:SS'), 'Australia/Victoria')
AT TIME ZONE 'Australia/West' , 'DD-Mon-YYYY HH24:Mi:SS'),'DD-Mon-YYYY HH24:Mi:SS'))
from dual
虽然有点混乱,但可以很好地满足我的需求。现在的问题是,这似乎没有考虑到夏令时。 10 月 10 日维多利亚州和西澳大利亚州之间的时差实际上是 3 小时,而不是 2 小时(正如我的查询当前返回的那样)。
现在这很奇怪,因为我认为 FROM_TZ 是处理 DST 的意思。更奇怪的是,如果我与 GMT 进行比较,我会得到正确的结果。
select FROM_TZ(to_timestamp( '10-Oct-2010 00:00:00','DD-Mon-YYYY HH24:Mi:SS'), 'GMT') AT TIME ZONE 'Australia/West'
from dual
FROM_TZ(TO_TIMESTAMP('10-OCT-2
------------------------------
10-OCT-10 08.00.00.000000000 AM AUSTRALIA/WEST
正确
select FROM_TZ(to_timestamp( '10-Oct-2010 00:00:00','DD-Mon-YYYY HH24:Mi:SS'), 'GMT') AT TIME ZONE 'Australia/Victoria'
from dual
FROM_TZ(TO_TIMESTAMP('10-OCT-2
------------------------------
10-OCT-10 11.00.00.000000000 AM AUSTRALIA/VICTORIA
正确
select FROM_TZ(to_timestamp( '10-Oct-2010 00:00:00','DD-Mon-YYYY HH24:Mi:SS'), 'Australia/Victoria') AT TIME ZONE 'Australia/West'
from dual
FROM_TZ(TO_TIMESTAMP('10-OCT-2
------------------------------
09-OCT-10 10.00.00.000000000 PM AUSTRALIA/WEST
错误。维多利亚州为 2010 年 10 月 10 日 00:00:00 AM,西澳大利亚州为 10 年 10 月 9 日下午 09:00:00。
那么问题来了,这是一个错误吗?或者我只是使用这个 FROM_TZ .. AT TIME ZONE 错误?
谢谢。
更新:
我认为这可能是 TO_CHAR 函数中的一个错误,它似乎得到了错误的 TZ 偏移量。虽然 FROM_TZ 可以正确地从 GMT 更改为维多利亚时间,但当您尝试从中提取 TZ 偏移量时,它会说它是 +10,而实际上它应该是 +11。
select TO_CHAR(FROM_TZ(to_timestamp( '10-Oct-2010 00:00:00','DD-Mon-YYYY HH24:Mi:SS'), 'Australia/Victoria'), 'TZH:TZM')
,FROM_TZ(to_timestamp( '10-Oct-2010 00:00:00','DD-Mon-YYYY HH24:Mi:SS'), 'GMT') AT TIME ZONE 'Australia/Victoria'
from dual
TO_CHAR(FROM_TZ(TO_TIMESTAMP(' FROM_TZ(TO_TIMESTAMP('10-OCT-2
--------------------------------------------------------------------------- ------------------------------
+10:00 10-OCT-10 11.00.00.000000000 AM AUSTRALIA/VICTORIA
Using Oracle 9.2i I need to get the offset of various dates from one timezones in relation to another timezone, previously I did this as such
select
(TO_DATE('10-Oct-2010 09:00:00','DD-Mon-YYYY HH24:Mi:SS') -
TO_DATE(TO_CHAR(FROM_TZ(to_timestamp( '10-Oct-2010 09:00:00','DD-Mon-YYYY HH24:Mi:SS'), 'Australia/Victoria')
AT TIME ZONE 'Australia/West' , 'DD-Mon-YYYY HH24:Mi:SS'),'DD-Mon-YYYY HH24:Mi:SS'))
from dual
Which while a bit messy, worked fine for my needs. Now the problem is this doesn't seem to be taking into account daylight savings. The time difference between Victoria and West Australia on the 10th Oct is actually 3 hours, not 2 hours ( as my query currently returns ).
Now this is odd, as I thought FROM_TZ is mean to handle DST. And even stranger, if I compare to GMT I get the correct results..
select FROM_TZ(to_timestamp( '10-Oct-2010 00:00:00','DD-Mon-YYYY HH24:Mi:SS'), 'GMT') AT TIME ZONE 'Australia/West'
from dual
FROM_TZ(TO_TIMESTAMP('10-OCT-2
------------------------------
10-OCT-10 08.00.00.000000000 AM AUSTRALIA/WEST
Correct
select FROM_TZ(to_timestamp( '10-Oct-2010 00:00:00','DD-Mon-YYYY HH24:Mi:SS'), 'GMT') AT TIME ZONE 'Australia/Victoria'
from dual
FROM_TZ(TO_TIMESTAMP('10-OCT-2
------------------------------
10-OCT-10 11.00.00.000000000 AM AUSTRALIA/VICTORIA
Correct
select FROM_TZ(to_timestamp( '10-Oct-2010 00:00:00','DD-Mon-YYYY HH24:Mi:SS'), 'Australia/Victoria') AT TIME ZONE 'Australia/West'
from dual
FROM_TZ(TO_TIMESTAMP('10-OCT-2
------------------------------
09-OCT-10 10.00.00.000000000 PM AUSTRALIA/WEST
Wrong. 10-Oct-2010 00:00:00 AM in Victoria is 09-OCT-10 09.00.00 PM in West Australia.
So the question is, is this a bug? or am I simply using this FROM_TZ .. AT TIME ZONE wrong?
Thanks.
Update:
I think this might be a bug in the TO_CHAR function, it seems to be getting the wrong TZ offset. While FROM_TZ can correctly change from GMT to Victoria time, when you try to extract the TZ offset from that, it says its +10, when it should be +11.
select TO_CHAR(FROM_TZ(to_timestamp( '10-Oct-2010 00:00:00','DD-Mon-YYYY HH24:Mi:SS'), 'Australia/Victoria'), 'TZH:TZM')
,FROM_TZ(to_timestamp( '10-Oct-2010 00:00:00','DD-Mon-YYYY HH24:Mi:SS'), 'GMT') AT TIME ZONE 'Australia/Victoria'
from dual
TO_CHAR(FROM_TZ(TO_TIMESTAMP(' FROM_TZ(TO_TIMESTAMP('10-OCT-2
--------------------------------------------------------------------------- ------------------------------
+10:00 10-OCT-10 11.00.00.000000000 AM AUSTRALIA/VICTORIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,TZH 和 TZM 是缩写的时区字符串,但它们不考虑夏令时。维多利亚的时区是+10:00。
也许 TZD 就是您所追求的。
http://download.oracle.com/docs/cd /B28359_01/olap.111/b28126/dml_commands_1029.htm
As far as I can tell, TZH and TZM are abbreviated time zone strings, but they don't take into account daylight savings. Victoria's time zone is +10:00.
Perhaps TZD is what you're after.
http://download.oracle.com/docs/cd/B28359_01/olap.111/b28126/dml_commands_1029.htm