简体   繁体   中英

How to convert date in mule 4?

I need to convert a date format

2020-07-28T21:00:00(RAML date-time only format)

to

Tue, 28 jul 2020 08:49:37 GMT format.

how to achieve this in mule-4?

%dw 2.0
output application/java
---
"2020-07-28T21:00:00" as DateTime
as String {format:"eee, dd MMM yyyy HH:mm:ss"}

https://simpleflatservice.com/mule4/Date_format.html

To format a date it's necessary to first coerce to a Date format then format it to the desired Date format as did below

%dw 2.0
output application/java
---
"2020-07-28T21:00:00" as DateTime
as String {format:"eee, dd MMM yyyy HH:mm:ss"}

o/p of this will be:

Tue, 28 Jul 2020 21:00:00

here addition to this I would like to say that this is the default GMT format

but if you want to convert any date format for example GMT to IST then you have to do as in the below code

%dw 2.0
output application/java
---
(now() as DateTime >> "IST")
as String {format:"eee, dd MMM yyyy HH:mm:ss"}

in above code at the time when I am answering this question now() is giving the time as 2021-02-03T07:08:37.002Z[GMT] but I want my answer in IST so I changed it first to IST and then in the desired format.

so final o/p of this will be in IST as below:

Wed, 03 Feb 2021 12:42:59

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