【发布时间】: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
我需要转换 NiFi 中的日期:
2022-11-22 00:00:00
至:
2022-11-22T00:00:00.000Z(ISO 8601)
有人可以帮我转换这个日期吗?
【问题讨论】:
标签: json date text type-conversion apache-nifi
您可以在 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": "&"
}
}
]
【讨论】:
如果您(或可以)将此信息作为属性,则可以使用 NiFi 的表达式语言对其进行转换。
例如,像这样:${my_attribute:toDate("yyyy-MM-dd HH:mm:ss", "Europe/Paris"):format("yyyy-MM-dd'T'HH:mm:ss'Z'")}
【讨论】: