How to convert milliseconds to date format using dataweave? 🕑

Are you using Twitter connector and want to convert the milliseconds date format to the normal 24/03/2020 date format? In order to convert into desired date format, we must use Dataweave 1.0 using the Transform message component in Anypoint Studio




Date format Dataweave solution for string variable


date : ("17545443526000" as :number / 1000) as :datetime as :string {format:"yyyy/dd/MM"}

Date format Dataweave solution for a number variable


date : (17545443526000/ 1000) as :datetime as :string {format:"yyyy/dd/MM"}

Quick tip:

How to convert a date (string) format to "yyyy-MM-dd" format

%dw 2.0
output application/json
var date='24-03-2020'
---
date as Date {format: 'dd-MM-yyyy'} as String {format: 'yyyy-MM-dd'}

This article covers Dataweave 2.0 and Dataweave 1.0 code to convert date in desired formats Ex: "yyyy-MM-dd". Its a simple and most effective way to convert the date format in JSON/XML messages

Post a Comment

0 Comments