简体   繁体   English

DateWeaver日期字段转换不起作用-Mule

[英]DateWeaver date field conversion not working - Mule

In DataWeaver documentation 10.8. 在DataWeaver文档10.8中。 Changing the Format of a Date https://developer.mulesoft.com/docs/dataweave#_date_time_operations 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
}

In the dataweaver preview it is looking fine as expected response ( Changed the date format). 在dataweaver预览中,它看起来像预期的响应一样好(更改了日期格式)。 I'm taking response in file component, But it is not converting the date in the format mentioned( Also kept logger right after the dataWeaver, not an expected response). 我正在文件组件中获取响应,但是它没有以提到的格式转换日期(也在dataWeaver之后保留了记录器,这不是预期的响应)。

Response getting as below 响应如下

{
"formatedDate1": "2003-10-01T23:57:59",
"formatedDate2": "2015-07-06T08:53:15"
 }

I have other query, here we are hardCoding the date inside the weaver. 我还有其他查询,这里我们在编织器中对日期进行硬编码。 If suppose we are taking the date field from Input parameter does we need to wrap the field inside || 如果假设我们要从Input参数获取date字段,是否需要将字段包装在|| . Example as below, will it work 下面的示例,它将正常工作

    %dw 1.0
    %output application/json
     %type mydate = :string { format: "YYYY/MM/dd" }
    ---
    {
     formatedDate1: |payload.dateField1| as :mydate,
     formatedDate2: payload.dateField1 as :mydate
    }

The above seems not to work for me. 以上似乎对我不起作用。 Please let me know the correct usage. 请让我知道正确的用法。 Thanks in advance 提前致谢

Try this: 尝试这个:

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

Output: 输出:

{
  "formatedDate1": "2003-10-01",
  "formatedDate2": "2015-07-06"
}

The difference is the datatype from :string to :date: : 区别在于数据类型从:string:date: ::

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

It seems the result doesn't change to / . 看来结果不会更改为/ This is probably a bug. 这可能是一个错误。

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

Try this 尝试这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM