将“yyyy-MM-dd'T'HH:mm:ss.SSSZ”时间戳转换为“yyyyMMdd”

问题描述 投票:0回答:1

示例输入:

{
  "transactionDateTime": "2023-12-05T16:56:15.912Z"
}

DataWeave 代码:

%dw 2.0
import * from dw::core::Strings

var date = payload.transactionDateTime as LocalDateTime {format: "yyyy-MM-dd'T'HH:mm:ss.SSSZ"} as String {format: "yyyyMMdd"}
output application/json  
---
{
    "k": date
}

以下是错误:

Cannot coerce String (2023-12-05T16:56:15.912Z) to LocalDateTime, caused by: Unknown pattern letter: T

14| var CURRENTDATEOriginalPostDate = payload.transactionDateTime as LocalDateTime {format:"yyyy-MM-ddTHH:mm:ss.SSSZ"} as String {format:"yyyy-MM-dd"}
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Trace:
  at main::main (line: 14, column: 35)
mule dataweave mulesoft mule4 anypoint-studio
1个回答
0
投票

在这种情况下,“Z”不是文字。可以使用日期时间格式字符“X”(区域偏移“Z”表示零)。

%dw 2.0
output application/json
---
{ 
    k: payload.transactionDateTime as LocalDateTime {format: "yyyy-MM-dd'T'HH:mm:ss.SSSX"} as String {format: "yyyyMMdd"}
}

输出:

{
  "k": "20231205"
}
© www.soinside.com 2019 - 2024. All rights reserved.