跳转至

Convert a string to timestamp(将字符串转换为时间戳(Convert a string to timestamp))

Supported in: Batch, Faster, Streaming

Returns the timestamp given a formatted string in accordance to the Java DateTimeFormatter. The default formats are yyyy-MM-dd'T'HH:mm:ss.SSSXXX and yyyy-MM-dd. The formats are run in order, the first matching format will be returned.

Expression categories: Cast, Datetime

Declared arguments

  • String: String column to convert to timestamp.
    Expression\
  • optional Formats: Format defaults to ISO8601 yyyy-MM-dd'T'HH:mm:ss.SSSXXX and yyyy-MM-dd.
    List\>
  • optional Time zone: Used to parse formats that do not include a timezone. If the format also includes a zone, this parameter will override it - see examples for details.
    TimeZone

Output type: Timestamp

Examples

Example 1: Base case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd'T'HH\:mm:ss.SSSSSSX]
  • Time zone: null
timestamp Output
2020-04-28T01:30:02.005110Z 2020-04-28T01:30:02.00511Z

Example 2: Base case

Argument values:

  • String: timestamp
  • Formats: null
  • Time zone: null
timestamp Output
2020-04-28T01:30:02.005Z 2020-04-28T01:30:02.005Z

Example 3: Base case

Argument values:

  • String: timestamp
  • Formats: null
  • Time zone: null
timestamp Output
2020-04-28 2020-04-28T00:00:00Z

Example 4: Base case

Argument values:

  • String: timestamp
  • Formats: [dd-yyyy-MM HH\:mm:ss, yyyy-MM-dd]
  • Time zone: null
timestamp Output
28-2020-04 10:09:00 2020-04-28T10:09:00Z
2020-04-28 2020-04-28T00:00:00Z

Example 5: Base case

Argument values:

  • String: timestamp
  • Formats: [yyyy-DDD HH\:mm:ss]
  • Time zone: null
timestamp Output
2022-334 10:09:00 2022-11-30T10:09:00Z

Example 6: Base case

Argument values:

  • String: timestamp
  • Formats: [dd MMMM yyyy HH\:mm:ss]
  • Time zone: null
timestamp Output
30 November 2022 10:09:00 2022-11-30T10:09:00Z

Example 7: Base case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd h\:mm:ss a]
  • Time zone: null
timestamp Output
2022-11-30 1:30:00 PM 2022-11-30T13:30:00Z

Example 8: Base case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd HH\:m:ss]
  • Time zone: null
timestamp Output
2022-11-30 13:9:00 2022-11-30T13:09:00Z

Example 9: Base case

Argument values:

  • String: timestamp
  • Formats: [dd-MMM-yyyy HH\:mm:ss]
  • Time zone: null
timestamp Output
30-Nov-2022 10:09:00 2022-11-30T10:09:00Z

Example 10: Base case

Argument values:

  • String: timestamp
  • Formats: [yyyy-DDD]
  • Time zone: null
timestamp Output
2022-334 2022-11-30T00:00:00Z

Example 11: Base case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd HH\:mm:s]
  • Time zone: null
timestamp Output
2022-11-30 13:09:0 2022-11-30T13:09:00Z

Example 12: Base case

Argument values:

  • String: timestamp
  • Formats: [yy-MM-dd HH\:mm:ss]
  • Time zone: null
timestamp Output
22-11-30 10:09:00 2022-11-30T10:09:00Z

Example 13: Base case

Argument values:

  • String: timestamp
  • Formats: [dd-MMM-yyyy HH\:mm:ss]
  • Time zone: null
timestamp Output
01-Nov-2023 10:09:00 2023-11-01T10:09:00Z

Example 14: Base case

Argument values:

  • String: timestamp
  • Formats: [dd-MMM-yyyy HH\:mm:ss]
  • Time zone: null
timestamp Output
01-NOV-2023 10:09:00 2023-11-01T10:09:00Z

Example 15: Base case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd HH\:mm:ss z]
  • Time zone: null
timestamp Output
2022-11-30 10:09:00 PST 2022-11-30T18:09:00Z

Example 16: Base case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd'T'HH\:mm:ss.SSS;z]
  • Time zone: null
timestamp Output
2022-11-29T09:50:04.187;EST 2022-11-29T14:50:04.187Z

Example 17: Base case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd'T'HH\:mm:ss.SSSXXX]
  • Time zone: null
timestamp Output
2022-11-29T09:50:04.187-05:00 2022-11-29T14:50:04.187Z

Example 18: Base case

Argument values:

  • String: timestamp
  • Formats: [dd-yyyy-MM HH\:mm:ss]
  • Time zone: Australia/Sydney
timestamp Output
28-2020-04 04:12:00 2020-04-28T04:12:00+10:00

Example 19: Base case

Argument values:

  • String: timestamp
  • Formats: [dd-yyyy-MM HH\:mm:ss]
  • Time zone: +10
timestamp Output
28-2020-04 04:12:00 2020-04-28T04:12:00+10:00

Example 20: Null case

Argument values:

  • String: timestamp
  • Formats: [dd-yyyy-MM HH\:mm:ss, yyyy-MM-dd]
  • Time zone: null
timestamp Output
202021-04-28 null

Example 21: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd'T'HH\:mm:ss.SSS;v]
  • Time zone: null
timestamp Output
2022-11-29T09:50:04.187;Australia/Sydney 2022-11-28T22:50:04.187Z

Example 22: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd'T'HH\:mm:ss.SSS;ZZZ]
  • Time zone: Australia/Sydney
timestamp Output
2022-11-29T09:50:04.187;-0500 2022-11-29T03:50:04.187Z

Example 23: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd'T'HH\:mm:ss.SSS;z]
  • Time zone: Australia/Sydney
timestamp Output
2022-11-29T09:50:04.187;EST 2022-11-28T22:50:04.187Z

Example 24: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd hh\:mm:ss a]
  • Time zone: null
timestamp Output
2022-11-30 10:09:00 AM 2022-11-30T10:09:00Z

Example 25: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd hh\:mm:ss a]
  • Time zone: null
timestamp Output
2022-11-30 10:09:00 PM 2022-11-30T22:09:00Z

Example 26: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyyDDD]
  • Time zone: UTC
timestamp Output
2023010 2023-01-10T00:00:00Z

Example 27: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyyDDD]
  • Time zone: EST
timestamp Output
2023010 2023-01-10T05:00:00Z

Example 28: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyyDDD]
  • Time zone: null
timestamp Output
2023010 2023-01-10T00:00:00Z

Example 29: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyyMMddHHmmss]
  • Time zone: UTC
timestamp Output
20230110000000 2023-01-10T00:00:00Z

Example 30: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyyMMddHHmmss]
  • Time zone: null
timestamp Output
20230110000000 2023-01-10T00:00:00Z

Example 31: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd'T'HH\:mm:ss.SSSXXX;z]
  • Time zone: null
timestamp Output
2022-11-29T09:50:04.187Z;EST 2022-11-29T09:50:04.187Z

Example 32: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd'T'HH\:mm:ss.SSSSSSX]
  • Time zone: null
timestamp Output
2020-04-28T01:30:02.005112Z 2020-04-28T01:30:02.005112Z


中文翻译


将字符串转换为时间戳(Convert a string to timestamp)

支持:批处理(Batch)、快速处理(Faster)、流处理(Streaming)

根据 Java DateTimeFormatter 规范,返回格式化字符串对应的时间戳。默认格式为 yyyy-MM-dd'T'HH:mm:ss.SSSXXXyyyy-MM-dd。系统按顺序尝试各格式,返回首个匹配格式的结果。

表达式类别: 类型转换(Cast)、日期时间(Datetime)

声明的参数

  • 字符串(String): 要转换为时间戳的字符串列。
    Expression\
  • 可选 格式(Formats): 默认格式为 ISO8601 yyyy-MM-dd'T'HH:mm:ss.SSSXXXyyyy-MM-dd
    List\>
  • 可选 时区(Time zone): 用于解析不含时区信息的格式。若格式本身包含时区,此参数将覆盖该时区——详见示例。
    TimeZone

输出类型: Timestamp

示例

示例 1:基础情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyy-MM-dd'T'HH\:mm:ss.SSSSSSX]
  • 时区: null
timestamp 输出
2020-04-28T01:30:02.005110Z 2020-04-28T01:30:02.00511Z

示例 2:基础情况

参数值:

  • 字符串: timestamp
  • 格式: null
  • 时区: null
timestamp 输出
2020-04-28T01:30:02.005Z 2020-04-28T01:30:02.005Z

示例 3:基础情况

参数值:

  • 字符串: timestamp
  • 格式: null
  • 时区: null
timestamp 输出
2020-04-28 2020-04-28T00:00:00Z

示例 4:基础情况

参数值:

  • 字符串: timestamp
  • 格式: [dd-yyyy-MM HH\:mm:ss, yyyy-MM-dd]
  • 时区: null
timestamp 输出
28-2020-04 10:09:00 2020-04-28T10:09:00Z
2020-04-28 2020-04-28T00:00:00Z

示例 5:基础情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyy-DDD HH\:mm:ss]
  • 时区: null
timestamp 输出
2022-334 10:09:00 2022-11-30T10:09:00Z

示例 6:基础情况

参数值:

  • 字符串: timestamp
  • 格式: [dd MMMM yyyy HH\:mm:ss]
  • 时区: null
timestamp 输出
30 November 2022 10:09:00 2022-11-30T10:09:00Z

示例 7:基础情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyy-MM-dd h\:mm:ss a]
  • 时区: null
timestamp 输出
2022-11-30 1:30:00 PM 2022-11-30T13:30:00Z

示例 8:基础情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyy-MM-dd HH\:m:ss]
  • 时区: null
timestamp 输出
2022-11-30 13:9:00 2022-11-30T13:09:00Z

示例 9:基础情况

参数值:

  • 字符串: timestamp
  • 格式: [dd-MMM-yyyy HH\:mm:ss]
  • 时区: null
timestamp 输出
30-Nov-2022 10:09:00 2022-11-30T10:09:00Z

示例 10:基础情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyy-DDD]
  • 时区: null
timestamp 输出
2022-334 2022-11-30T00:00:00Z

示例 11:基础情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyy-MM-dd HH\:mm:s]
  • 时区: null
timestamp 输出
2022-11-30 13:09:0 2022-11-30T13:09:00Z

示例 12:基础情况

参数值:

  • 字符串: timestamp
  • 格式: [yy-MM-dd HH\:mm:ss]
  • 时区: null
timestamp 输出
22-11-30 10:09:00 2022-11-30T10:09:00Z

示例 13:基础情况

参数值:

  • 字符串: timestamp
  • 格式: [dd-MMM-yyyy HH\:mm:ss]
  • 时区: null
timestamp 输出
01-Nov-2023 10:09:00 2023-11-01T10:09:00Z

示例 14:基础情况

参数值:

  • 字符串: timestamp
  • 格式: [dd-MMM-yyyy HH\:mm:ss]
  • 时区: null
timestamp 输出
01-NOV-2023 10:09:00 2023-11-01T10:09:00Z

示例 15:基础情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyy-MM-dd HH\:mm:ss z]
  • 时区: null
timestamp 输出
2022-11-30 10:09:00 PST 2022-11-30T18:09:00Z

示例 16:基础情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyy-MM-dd'T'HH\:mm:ss.SSS;z]
  • 时区: null
timestamp 输出
2022-11-29T09:50:04.187;EST 2022-11-29T14:50:04.187Z

示例 17:基础情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyy-MM-dd'T'HH\:mm:ss.SSSXXX]
  • 时区: null
timestamp 输出
2022-11-29T09:50:04.187-05:00 2022-11-29T14:50:04.187Z

示例 18:基础情况

参数值:

  • 字符串: timestamp
  • 格式: [dd-yyyy-MM HH\:mm:ss]
  • 时区: Australia/Sydney
timestamp 输出
28-2020-04 04:12:00 2020-04-28T04:12:00+10:00

示例 19:基础情况

参数值:

  • 字符串: timestamp
  • 格式: [dd-yyyy-MM HH\:mm:ss]
  • 时区: +10
timestamp 输出
28-2020-04 04:12:00 2020-04-28T04:12:00+10:00

示例 20:空值情况

参数值:

  • 字符串: timestamp
  • 格式: [dd-yyyy-MM HH\:mm:ss, yyyy-MM-dd]
  • 时区: null
timestamp 输出
202021-04-28 null

示例 21:边界情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyy-MM-dd'T'HH\:mm:ss.SSS;v]
  • 时区: null
timestamp 输出
2022-11-29T09:50:04.187;Australia/Sydney 2022-11-28T22:50:04.187Z

示例 22:边界情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyy-MM-dd'T'HH\:mm:ss.SSS;ZZZ]
  • 时区: Australia/Sydney
timestamp 输出
2022-11-29T09:50:04.187;-0500 2022-11-29T03:50:04.187Z

示例 23:边界情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyy-MM-dd'T'HH\:mm:ss.SSS;z]
  • 时区: Australia/Sydney
timestamp 输出
2022-11-29T09:50:04.187;EST 2022-11-28T22:50:04.187Z

示例 24:边界情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyy-MM-dd hh\:mm:ss a]
  • 时区: null
timestamp 输出
2022-11-30 10:09:00 AM 2022-11-30T10:09:00Z

示例 25:边界情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyy-MM-dd hh\:mm:ss a]
  • 时区: null
timestamp 输出
2022-11-30 10:09:00 PM 2022-11-30T22:09:00Z

示例 26:边界情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyyDDD]
  • 时区: UTC
timestamp 输出
2023010 2023-01-10T00:00:00Z

示例 27:边界情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyyDDD]
  • 时区: EST
timestamp 输出
2023010 2023-01-10T05:00:00Z

示例 28:边界情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyyDDD]
  • 时区: null
timestamp 输出
2023010 2023-01-10T00:00:00Z

示例 29:边界情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyyMMddHHmmss]
  • 时区: UTC
timestamp 输出
20230110000000 2023-01-10T00:00:00Z

示例 30:边界情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyyMMddHHmmss]
  • 时区: null
timestamp 输出
20230110000000 2023-01-10T00:00:00Z

示例 31:边界情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyy-MM-dd'T'HH\:mm:ss.SSSXXX;z]
  • 时区: null
timestamp 输出
2022-11-29T09:50:04.187Z;EST 2022-11-29T09:50:04.187Z

示例 32:边界情况

参数值:

  • 字符串: timestamp
  • 格式: [yyyy-MM-dd'T'HH\:mm:ss.SSSSSSX]
  • 时区: null
timestamp 输出
2020-04-28T01:30:02.005112Z 2020-04-28T01:30:02.005112Z