When you need to format a Date as a String you using the same Java patterns as for the DateTimeFormatterBuilder

For example, let's say we want the output in the format yyyy-MM-dd’T’HH:mm:ss.SSS 

Date Time conversion examples in Mule 4 Dataweave 2.0



Dataweave Code:
%dw 2.0
output application/json
fun format(d: DateTime) = d as String {format: "yyyy-MM-dd'T'HH:mm:ss.SSS"}
---
{
CreatedDateTime: format(|2019-02-13T13:23:00.120Z| >> "CET"),
}

Result:
{
"CreatedDateTime": "2019-02-13T14:23:00.120"

Examples: 
%dw 2.0
output application/json
var utc = "UTC" as TimeZone
fun printFormattedDate()=(now() >> utc) as String
---
{
myDate: printFormattedDate()
}

Result:
{
"myDate": "2019-09-15T23:08:56.367Z"
}

Others:
"Date of Birth" : ($."DOB" as :date) as :string {format: "yyyy-MM-dd HH:mm:ss"}


Want to learn Mulesoft and ESB tutorials. Our blog provides the best articles on Mule4, Mule 3, Dataweave, Anypoint platform, and Anypoint Studio. We provide tutorials on creating mule applications, how to use different connectors, running DataWeave code, and solving issues. Let us know if you want to create a tutorial on any Mulesoft Tutorials