簡體   English   中英

Oracle - 將 UTC 日期轉換為美國本地日期時間格式

[英]Oracle - Convert UTC Date to Local Date Time US Format

我有 UTC 時區的日期時間,並希望將其轉換為美國日期時間格式 MM/DD/YYYY 並調整為本地時區。

通過腳本在幾個步驟中將其轉換...

您認為可以使用 SELECT 語句來實現嗎? 不確定我們是否可以知道服務器上配置的時區。 很高興得到一些建議。 謝謝。

Here is a step-by-step of the process

 I will start with a timestamp in UTC

    SQL> select timestamp '2021-07-01 09:00:00 +00:00' ts from dual;
    
    TS
    ---------------------------------------------------------------------
    01-JUL-21 09.00.00.000000000 AM +00:00

Assuming this is stored in some sort of table, the first thing we can do is convert it to the desired time zone. In my case, I live in Perth, Australia so I do:

    SQL> with my_table as (
      2  select timestamp '2021-07-01 09:00:00 +00:00' ts from dual
      3  )
      4  select ts at time zone 'Australia/Perth' as perth_time
      5  from my_table;
    
    PERTH_TIME
    ---------------------------------------------------------------
    01-JUL-21 05.00.00.000000000 PM AUSTRALIA/PERTH

9am UTC is 5pm in Perth (we're 8 hours in front).  Now I want that output in a format that I want, so I can TO_CHAR that in the normal way

SQL> with my_table as (
  2  select timestamp '2021-07-01 09:00:00 +00:00' ts from dual
  3  )
  4  select to_char(ts at time zone 'Australia/Perth','MM/DD/YYYY HH24:MI:SS') as perth_time
  5  from my_table;

PERTH_TIME
-------------------
07/01/2021 17:00:00

我們完成了

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM