web123456

Time and date format conversion under flinksql

The most common thing in flinksql is time format conversion, such as converting various time formats intoTIMESTAMP(3).
now() bigint-- CAST(TO_TIMESTAMP(log_time) as TIMESTAMP(3)) ,log_time=now()
localtimestamp timestamp(3)

timestamp – without brackets, timestamp(6)
now() 1403006911000 bigint – millisecond timestamp value 1528257600000
localtimestamp 1636272032500 timestamp(3) – millisecond timestamp
timestamp(3) 1636272032500 – millisecond timestamp
timestamp(9)
timestamp(6)

TIMESTAMP(9) TO_TIMESTAMP(BIGINT time)
TIMESTAMP(9) TO_TIMESTAMP(STRING time)
TIMESTAMP(9) TO_TIMESTAMP(STRING time, STRING format)
BIGINT TIMESTAMP_TO_MS(TIMTSTAMP time)
BIGINT TIMESTAMP_TO_MS(STRING time, STRING format)

TO_DATE(CAST(LOCALTIMESTAMP AS VARCHAR))

FROM_UNIXTIME(TIMESTAMP_TO_MS(localtimestamp)/1000, ‘yyyy-MM-dd HH:mm:ss’)

event_time 6 o'clock to 6 o'clock
time_pt as cast(to_timestamp(eventTime - 6 * 3600 * 1000) as TIMESTAMP(3)) – Offset 6 hours

date_format(to_timestamp(eventTime-636001000), ‘yyyy-MM-dd’) = date_format(to_timestamp((UNIX_TIMESTAMP(localtimestamp) -6*3600)*1000),‘yyyy-MM-dd’)

,gmt_modify TIMESTAMP(3) – ‘Update time’
,WATERMARK FOR gmt_modify AS gmt_modify - INTERVAL ‘60’ SECOND
TIMESTAMP_TO_MS(gmt_modify) - now()
Reference documentation:
https://ci.apache.org/projects/flink/flink-docs-master/zh/docs/dev/table/concepts/timezone/