【问题标题】:NiFi - Convert date in format ISO8601NiFi - 以 ISO8601 格式转换日期
【发布时间】:2022-11-23 20:02:48
【问题描述】:

我需要转换 NiFi 中的日期:

2022-11-22 00:00:00

至:

2022-11-22T00:00:00.000Z(ISO 8601)

有人可以帮我转换这个日期吗?

【问题讨论】:

    标签: json date text type-conversion apache-nifi


    【解决方案1】:

    您可以在 JoltTransformJSON 处理器中使用以下规范,假设您需要对属性的当前值进行转换(即 dt 嵌套在一个简单的 JSON 对象中), 2022-11-22 00:00:00从变量$now中提取

    [
      {
       // reformat by adding the milliseconds option
        "operation": "default",
        "spec": {
            "dt": "${now():format('yyyy-MM-ddHH:mm:ss.SSS')}"
        }
      },
      {
       // split and recombine the pieces of the attribute's value
        "operation": "modify-overwrite-beta",
        "spec": {
          "date": "=substring(@(1,dt),0,10)",
          "time": "=substring(@(1,dt),10,22)",
          "dt":"=concat(@(1,date),'T',@(1,time),'Z')"     
        }
      },
      {
       // pick only theoriginal tag name
        "operation": "shift",
        "spec": {
            "dt": "&"
        }
      }
    ]
    

    【讨论】:

      【解决方案2】:

      如果您(或可以)将此信息作为属性,则可以使用 NiFi 的表达式语言对其进行转换。

      例如,像这样:${my_attribute:toDate("yyyy-MM-dd HH:mm:ss", "Europe/Paris"):format("yyyy-MM-dd'T'HH:mm:ss'Z'")}

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多