如何在 Mule 数据编织中格式化日期
How to Format Date in Mule Data weave
我如何在 Dataweave 中格式化日期。我尝试使用 MuleSoft 文档中提到的选项。我在有效负载中的日期为
"noteDate": "2018-12-01 00:00:00",
我在 Dataweave 中的功能是
fun getFormattedDate(data) =
if ( data !=null ) data as String {format: "uuuu-MM-dd"}
else
null
但它根本没有格式化。预期输出为“2018-12-01”
试试这个。
%dw 2.0
output application/json
---
payload.noteDate as LocalDateTime {"format": "uuuu-MM-dd HH:mm:ss"} as String {"format": "uuuu-MM-dd"}
试试这个对 null 和 dateTime 值都有效的函数。
%dw 2.0
output application/json
fun GenericDate(dateTime) = (dateTime as LocalDateTime {format: "yyyy-MM-dd HH:mm:ss"} as Date) default null
---
GenericDate(payload.noteDate)
我如何在 Dataweave 中格式化日期。我尝试使用 MuleSoft 文档中提到的选项。我在有效负载中的日期为
"noteDate": "2018-12-01 00:00:00",
我在 Dataweave 中的功能是
fun getFormattedDate(data) =
if ( data !=null ) data as String {format: "uuuu-MM-dd"}
else
null
但它根本没有格式化。预期输出为“2018-12-01”
试试这个。
%dw 2.0
output application/json
---
payload.noteDate as LocalDateTime {"format": "uuuu-MM-dd HH:mm:ss"} as String {"format": "uuuu-MM-dd"}
试试这个对 null 和 dateTime 值都有效的函数。
%dw 2.0
output application/json
fun GenericDate(dateTime) = (dateTime as LocalDateTime {format: "yyyy-MM-dd HH:mm:ss"} as Date) default null
---
GenericDate(payload.noteDate)