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:
Result:
Examples:
Result:
Others:
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
%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
5 Comments
How to convert number to HH:mm:ss alone
ReplyDeleteexample : payload { time: 101122}
output : 10:11:22
Please try
ReplyDeletepayload.time as DateTime {format: "hh:mm:ss"}
yes, it is converted to the expected format. But value got change.
ReplyDeleteExpected value should be same as the payload value. Ex : payload { time:123456}
output: 12:34:56
if you observer in output value, just added ":" after every 2 digits
yes, it is converted to the expected format. But value got change.
ReplyDeleteExpected value should be same as the payload value. Ex : payload { time:123456}
output: 12:34:56
if you observer in output value, just added ":" after every 2 digits
Can you please check mail
ReplyDelete