2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

OracleでISO 8601形式の日付を出力する

Posted at

timestamp型の日時をUTCへ変換したうえでISO 8601形式で出力します。

前提条件

  • ISO 8601形式で表示させる日付列の型はtimestamp型であること
  • 日付列の各行の値は、DBMS(Oracle)のタイムゾーンに準じたものであること(例えば、DBMSのタイムゾーンがJSTである場合はJSTで日付がセットされていること)

コード

to_char(
    SYS_EXTRACT_UTC(<timestamp型の日付>),
    'YYYY-MM-DD"T"HH24:MI:SS.FF3"+0000"'
)

select
    sessiontimezone,
    to_timestamp('2019-01-21 09:12:27.804000') as jst,
    to_timestamp(sys_extract_utc(to_timestamp('2019-01-21 09:12:27.804000'))) as utc,
    to_char(
        sys_extract_utc(to_timestamp('2019-01-21 09:12:27.804000')),
        'YYYY-MM-DD"T"HH24:MI:SS.FF3"+0000"'
    ) as utc_iso8601
from dual;

結果

image.png

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?