0

Using input payload of

{
"Date": "2025-09-09T18:03:06.830"
}

I'm trying to get an output of

"2025-09-09T18:03:06.830Z"

I've tried this DataWeave

%dw 2.0
output application/json
---
payload.Date as String {format: "yyyy-MM-dd'T'HH:mm:ss.SSSZ"}

But my output is coming back as

"2025-09-09T18:03:06.830"

Without the Z at the end of the milliseconds

I've also tried

%dw 2.0
output application/json
---
payload.Date as String {format: "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"}

With no luck

I can't seem to find as DateTime formatting that is helping me either. I've also found outputs with 2 milliseconds and a Z but not 3 (such as the basic payload.Date as DateTime output)

1
  • This question is similar to: Dataweave Date Formatting with Timezone. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Sep 9 at 20:42

1 Answer 1

0

Interesting find, so if I use

(payload.Date as DateTime) as String {format: "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"}

I get the string that I'm looking for.

A couple of conversions, but it gets the job done.

Sign up to request clarification or add additional context in comments.

1 Comment

They are not additional conversions. The date/time formatting only makes sense when converting from/to Date/Time types and String. String or Date/Times don't have formats in DataWeave, like Java. The input here is a String and the output is a String. You need to convert to a Date/Time type first to change the output format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.