0
Input String: 201801
Output String format: 01.2018

我尝试使用以下但它不起作用,我还在“类型强制表” https://docs.mulesoft.com/mule-user-guide/v/3.8/dataweave-types中查找了字符串到日期转换/强制表#type-coercion-table。我没有找到可以帮助我解决这个问题的东西。

as :date {format: "yyyyww"} as :string {format: "ww.yyyy"}

欣赏是否有人有任何想法要分享。

4

1 回答 1

0

如果您不介意字符串黑客,您可以移动输入字符串的各个部分:

%dw 1.0
%output application/json
%var inputDate = "201801"
---
{
    outputDate: inputDate[4..5] ++ "." ++ inputDate[0..3]
}

的输出是

{
  "outputDate": "01.2018"
}

但是,如果输入日期字符串有可能为空,或者如果它短于 6 个字符,则上述内容不是 null 安全的,您将收到运行时错误。您可以通过检查 DW 中的日期来解决此问题,例如

outputDate: (inputDate[4..5] ++ "." ++ inputDate[0..3]) when inputDate != null and ( sizeOf inputDate ) == 6 otherwise null
于 2018-07-29T20:52:15.377 回答