在DataWeaver文档10.8中。 Changing the Format of a Date
https://developer.mulesoft.com/docs/dataweave#_date_time_operations
Below is the transform
%dw 1.0
%output application/json
%type mydate = :string { format: "YYYY/MM/dd" }
---
{
formatedDate1: |2003-10-01T23:57:59| as :mydate,
formatedDate2: |2015-07-06T08:53:15| as :mydate
}
在dataweaver预览中,它看起来很正常,符合预期的响应(更改了日期格式)。 我正在文件组件中进行响应,但它没有按照提到的格式转换日期(也在dataWeaver之后保留logger,而不是预期的响应)。
回复如下
{
"formatedDate1": "2003-10-01T23:57:59",
"formatedDate2": "2015-07-06T08:53:15"
}
我有其他查询,这里我们正在编织织布机内的日期。如果假设我们从Input参数中获取日期字段,我们需要将字段包装在||
内。如下所示,是否可行
%dw 1.0
%output application/json
%type mydate = :string { format: "YYYY/MM/dd" }
---
{
formatedDate1: |payload.dateField1| as :mydate,
formatedDate2: payload.dateField1 as :mydate
}
以上似乎对我不起作用。请告诉我正确的用法。 提前致谢
答案 0 :(得分:2)
试试这个:
%dw 1.0
%output application/json
%type mydate = :date { format: "yyyy/M/d" }
---
{
formatedDate1: |2003-10-01T23:57:59| as :mydate,
formatedDate2: |2015-07-06T08:53:15| as :mydate
}
输出:
{
"formatedDate1": "2003-10-01",
"formatedDate2": "2015-07-06"
}
区别在于从:string
到:date:
的数据类型:
%type mydate = **:date** { format: "yyyy/M/d" }
结果似乎没有变为/
。这可能是一个错误。
答案 1 :(得分:0)
%dw 1.0
%output application/json
%type mydate = :string { format: "YYYY/M/d" }
---
{
formatedDate1: |2003-10-01T23:57:59| as :mydate,
formatedDate2: |2015-07-06T08:53:15| as :mydate
}
试试这个