简体   繁体   中英

Mule Dataweave Date Time Conversion from Full to Short

I am attempting to convert this datetime string from this format:

'Wed, 09 Aug 2017 20:16:59 +0000'

To this format:

'08092017'

I am using dataweave. Here is my code:

order-date:payload.order.date_created 
as :localdatetime {format: "E, dd M yyyy hh:mm:ss Z"} 
as :string {format: "MMddyyyy"},

I still get the error - Cannot coerce a :string to a :localdatetime, caused by :Text 'Wed, 09 Aug 2017 20:16:59 +0000' could not be parsed at index 8

index 8 appears to the time zone offset, but according to java docs the timezone is specified as uppercase Z

If anyone stumbles across this from a google... I had the formatting incorrect. Here is the corrected version:

order-date:payload.order.date_created 
as :localdatetime {format: "E, dd MMM yyyy HH:mm:ss Z"} 
as :string {format: "MMddyyyy"},

You should be able to easily do this using dataweave date formatting. Here first you need to convert it to local datetime and then to date format you desire to convert to. Giving some example of date format conversions from Mulesoft documentaions { dates : { date1: normalize("26-JUL-16") as :date {format: "d-MMM-yy"} as :string {format: "yyyy-MM-dd"}, date2: normalize("26/JUL/16") as :date {format: "d-MMM-yy"} as :string {format: "yyyy-MM-dd"}, date3: normalize("26.JUL.16") as :date {format: "d-MMM-yy"} as :string {format: "yyyy-MM-dd"} } }

Please read below links for more understanding of date formatting.

https://docs.mulesoft.com/mule-user-guide/v/3.8/dataweave-examples#parse-dates-with-different-separators https://docs.mulesoft.com/mule-user-guide/v/3.8/dataweave-operators#date-time-operations

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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