Using input payload of
{
"Date": "2025年09月09日T18:03:06.830"
}
I'm trying to get an output of
"2025年09月09日T18: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月09日T18: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)
-
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.aled– aled2025年09月09日 20:42:19 +00:00Commented Sep 9, 2025 at 20:42
1 Answer 1
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
aled
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.