简体   繁体   English

如何在Oracle SQL中将PDT转换为日期时间对象?

[英]How to convert PDT into a date time object in Oracle sql?

If I have dates that are in this format: Sep-29-07 13:45:00 PDT 如果我的日期采用以下格式: Sep-29-07 13:45:00 PDT

How would I convert this into a Date object in oracle 11g? 我如何将其转换为oracle 11g中的Date对象? I have tried this: 我已经试过了:

SELECT TO_DATE(PublishDate, 'MON-DD-YY HH24:MI:SS')
FROM Order;

But I am getting an error saying: 但我收到一个错误消息:

ORA-01830: date format picture ends before converting entire input string ORA-01830:日期格式图片在转换整个输入字符串之前结束

If you have only one time zone's dates, you can just ignore the timezone part using: 如果您只有一个时区的日期,则可以使用以下命令忽略时区部分:

select to_date(PublishDate, 'MON-DD-YY HH24:MI:SS "PDT"') 
from Orders;

If you plan to support multiple timezones, then store them with timestamp with time zone format. 如果您打算支持多个时区,则将它们与timestamp with time zone格式的timestamp with time zone存储。 use correct timezone abbreviation (PST instead of PDT - See this ) and convert the string, use to_timestamp_tz . 使用正确的时区缩写(用PST代替to_timestamp_tz 参见this )并转换字符串,使用to_timestamp_tz

select to_timestamp_tz(PublishDate, 'MON-DD-YY HH24:MI:SS TZR') 
from Orders;

or perhaps, convert them in one local time zone. 或者,可以将它们转换为一个本地时区。 See this answer for that 看到这个答案

You can ignore the timezone by using: 您可以使用以下方法忽略时区:

SELECT TO_DATE(SUBSTR(PublishDate, 1, length(PublishDate) - 4), 'MON-DD-YY HH24:MI:SS')

However, if you want to handle different timezones, you need to store the standard format, something like 'America/Los_Angeles' . 但是,如果要处理不同的时区,则需要存储标准格式,例如'America/Los_Angeles'

For example: 例如:

SELECT TO_TIMESTAMP_TZ(PublishDate, 'MON-DD-YY HH24:MI:SS TZR')
from (select 'Sep-29-07 13:45:00 America/Los_Angeles' as PublishDate from dual) x;

You can this modify this with 'PDT' , but that is not acceptable by itself. 您可以使用'PDT'对此进行修改,但这本身是不可接受的。

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

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