将字符串 ISO-8601 日期转换为 oracle 的时间戳数据类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26671557/
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-19 02:35:29  来源:igfitidea点击:

Convert String ISO-8601 date to oracle's timestamp datatype

databaseoracleiso8601

提问by hades

I have a ISO-8601 date in VARCHAR2 type, how can i convert that String date to timestamp in oracle db?

我有一个 VARCHAR2 类型的 ISO-8601 日期,如何将该字符串日期转换为 oracle db 中的时间戳?

Date Example: "2014-09-12T11:53:06+00:00"

日期示例:“2014-09-12T11:53:06+00:00”

Maybe is something like the following but i not sure what is the format.

也许类似于以下内容,但我不确定格式是什么。

SELECT to_timestamp_tz ('2014-09-12T11:53:06+00:00', ????) FROM DUAL

回答by Alex Poole

The date format model elements are listed in the Datetime Format Models documentation:

日期格式模型元素列在日期时间格式模型文档中

SELECT to_timestamp_tz ('2014-09-12T11:53:06+00:00', 'YYYY-MM-DD"T"HH24:MI:SSTZH:TZM')
FROM DUAL

TO_TIMESTAMP_TZ('2014-09-12T11:53:06+00:00','YYYY-MM-DD"T"HH24:MI:SSTZH:TZM')
---------------------------------------------------------------------------
12-SEP-14 11.53.06.000000000 +00:00

The fixed Tcan be included as a character literal:

固定T可以作为字符文字包含:

You can include these characters in a date format model:

  • Punctuation such as hyphens, slashes, commas, periods, and colons
  • Character literals, enclosed in double quotation marks

您可以在日期格式模型中包含这些字符:

  • 标点符号,例如连字符、斜线、逗号、句点和冒号
  • 字符文字,用双引号括起来

TZHis tome zone hour, and TZMis time zone minutes. The rest are more common model elements.

TZH是时区小时,TZM是时区分钟。其余的是更常见的模型元素。