0
votes

I am trying to convert a string from payload to format dd/mm/yyyy

Here is the string from payload:

Mar 9, 2016 04:19:33 PM

My Dataweave conversion:

timestamp: payload.metas.datas[0].timestamp as :datetime {format: "MMM d, yyyy hh:mm:ss a"}

I am getting the following error:

Cannot coerce a :string to a :datetime, caused by :Text 'Mar 9, 2016 04:19:33 PM' could not be parsed: Unable to obtain ZonedDateTime from TemporalAccessor: DateTimeBuilder[, ISO, null, 2016-03-09, 16:19:33], type org.threeten.bp.format.DateTimeBuilder.

Can anyone advise how this should be done ?

Thanks a lot. Mike

2

2 Answers

2
votes

Date could not be parsed as it cant decide for timezone. You can try following code

timestamp: payload.metas.datas[0].timestamp as :localdatetime {format: "MMM d, yyyy hh:mm:ss a"} as :string {format: "dd/mm/yyyy"}

HTH

0
votes

This worked for me.

timestamp: payload.metas.datas[0].timestamp as LocalDateTime {format: "MMM d, yyyy H:mm:ss a"} as String {format: "yyyy-MM-dd HH:mm:ss"}