简体   繁体   English

将 oracle.sql.timestamptz 转换为带有时区的 postgresql 时间戳

[英]Convert oracle.sql.timestamptz to postgresql timestamp with timezone

Sorry, but i`m noob and i need your advices.对不起,但我是菜鸟,我需要你的建议。 I have some result set from oracle with timestamptz, i get string value of this timestamptz which like我从 oracle 得到了一些带有时间戳的结果集,我得到了这个时间戳的字符串值,它喜欢

2014-1-10 13.47.56.0 7:0 2014-1-10 13.47.56.0 7:0

and then I need put it in postgresql-request in some function which takes timestamp with timezone.然后我需要将它放在 postgresql-request 中的某个函数中,该函数需要带时区的时间戳。 How can I convert this this string to timestamp with timezone in java?如何将此字符串转换为 java 中带时区的时间戳? I tried do something look like TO_TIMESTAMP_TZ("2014-1-10 13.47.32.0 7:0","YYYY-MM-DD HH24:MI:SS.FF TZH:TZM") but it didn`t work for me.我尝试做一些类似于TO_TIMESTAMP_TZ("2014-1-10 13.47.32.0 7:0","YYYY-MM-DD HH24:MI:SS.FF TZH:TZM")但它对我不起作用。 Help me, please.请帮帮我。

I don't know of a function TO_TIMESTAMP_TZ() in Postgres.我不知道 Postgres 中的TO_TIMESTAMP_TZ()函数。 You probably mean to_timestamp() .你可能是说to_timestamp()

I also don't know of a template patterns TZH:TZM .我也不知道模板模式TZH:TZM You could use the AT TIME ZONE construct.您可以使用AT TIME ZONE构造。

And data is quoted with single quotes ;数据用单引号引用 double quotes are for identifiers.双引号用于标识符。

This works for me:这对我有用:

SELECT to_timestamp('2014-1-10 13.47.32.0', 'YYYY-MM-DD HH24:MI:SS.MS')::timestamp
       AT TIME ZONE '-7:0';  -- shift back

It would be smarter to output timestamps in ISO 8601 format with TZR (time zone region) in Oracle, which is less ambiguous.使用 Oracle 中的TZR (时区区域)以 ISO 8601 格式输出时间戳会更智能,这不会那么模糊。 Details in the Oracle manual. Oracle 手册中的详细信息。

Or better yet, UTC timestamps (without 0 offset), which you can cast to timestamptz directly in Postgres:或者更好的是,UTC 时间戳(没有0偏移),您可以直接在 Postgres 中将其转换为timestamptz

SELECT '2014-01-10 06:47:32+0'::timestamptz;

Or UNIX epochs, which can be fed to the second form of to_timestamp() .或者 UNIX 纪元,它可以提供给to_timestamp()的第二种形式。

SELECT to_timestamp(1389336452);

Details about timestamps in Postgres: Postgres 中时间戳的详细信息:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM