All Products
Search
Document Center

Realtime Compute for Apache Flink:TO_TIMESTAMP_TZ

Last Updated:Dec 10, 2024

Converts a date value of the VARCHAR type into the TIMESTAMP type of a specific time zone corresponding to the Flink runtime environment.

Syntax

TIMESTAMP TO_TIMESTAMP_TZ(VARCHAR date, VARCHAR timezone)
TIMESTAMP TO_TIMESTAMP_TZ(VARCHAR date, VARCHAR format, VARCHAR timezone)

Input parameters

Parameter

Data type

Description

date

VARCHAR

The input date of the VARCHAR type.

format

VARCHAR

The format of the input date. Default value: yyyy-MM-dd HH:mm:ss.

timezone

VARCHAR

The time zone of the input date, such as Asia/Shanghai.

Note

When configured to a non-standard time zone, the parameter defaults to UTC.

Example

Note

In this example, the time zone of the local system where Flink operates is Asia/Shanghai (GMT+8).

  • Test data

    Table T1

    timestamp1(VARCHAR)

    format1(VARCHAR)

    timezone1(VARCHAR)

    1970-01-01 00:00:00

    yyyy-MM-dd HH:mm:ss

    /

    timestamp2(VARCHAR)

    format2(VARCHAR)

    timezone2(VARCHAR)

    1970-01-01 00:00:00

    yyyy-MM-dd HH:mm:ss

    Asia/Shanghai

    timestamp3(VARCHAR)

    format3(VARCHAR)

    timezone3(VARCHAR)

    1970-01-01 00:00:00

    yyyy-MM-dd HH:mm:ss

    America/New_York

  • Test statement

    SELECT  
         TO_TIMESTAMP_TZ(timestamp1, timezone1) AS var1,
         TO_TIMESTAMP_TZ(timestamp2, format2, timezone2) AS var2,
         TO_TIMESTAMP_TZ(timestamp3, format3, timezone3) AS var3
    FROM T1;
  • Test result

    var1(VARCHAR)

    var2(VARCHAR)

    var3(VARCHAR)

    1970-01-01 08:00:00

    1970-01-01 00:00:00

    1970-01-01 13:00:00