I have the following string 20170912113456 and i want to convert it to this format 2017/09/12 11:34:56 using Dataweave Mule.
Any ideas about how to do it ?
2 Answers
I would recommend first converting your input date string into a Dataweave localdatetime object. Then you can output the date object back to a string of any format.
%dw 1.0
%output application/json
---
formattedDate: flowVars.date as :localdatetime{format: "yyyyMMddHHmmss"} as :string{format:"yyyy/mm/dd HH:mm:ss"}
If you interested in learning the inner-working check out my converting string dates to Java Date Objects in Mule tutorial, https://youtu.be/XqI_Kii9RzA
Comments
You can try few things like formatting to data and then to string based on below example.
myDate: ((payload as :string) as :date {format: "yyyyMMdd"}) as :string {format: "MM-dd-yyyy"}
For a better understanding the Date Time operations please go through below link.
https://docs.mulesoft.com/mule-user-guide/v/3.8/dataweave-operators#date-time-operations