1

在 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 之后保留记录器,而不是预期的响应)。

得到如下响应

{
"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
    }

以上似乎对我不起作用。请告诉我正确的用法。提前致谢

4

2 回答 2

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"
}

不同之处在于从:stringto的数据类型:date:

%type mydate = **:date** { format: "yyyy/M/d" }

结果似乎没有变为/. 这可能是一个错误。

于 2015-09-22T14:37:40.233 回答
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
}

试试这个

于 2015-09-21T12:24:30.667 回答