json NiFi -将日期转换为ISO 8601格式

bvhaajcl  于 2022-11-26  发布在  其他
关注(0)|答案(2)|浏览(205)

我需要在NiFi中转换日期:
2022年11月22日00:00:00
收件人:
2022年11月22日00:00:00.000Z(ISO 8601标准)
有人能帮我转换这个日期吗?

qv7cva1a

qv7cva1a1#

假设需要转换属性的当前值(即嵌套在简单JSON对象中的dt),可以在JoltTransformJSON处理器中使用以下规范,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": "&"
    }
  }
]
olhwl3o2

olhwl3o22#

如果您(或可以)将此信息作为属性,则可以使用NiFi的表达式语言对其进行转换。
比如说,像这样的事情:${my_attribute:toDate("yyyy-MM-dd HH:mm:ss", "Europe/Paris"):format("yyyy-MM-dd'T'HH:mm:ss'Z'")}

相关问题