now() - current time issue for mule app deployed on Any point platform

131 views Asked by At

I have a question about the current time issue in our Mule App, which is deployed on any point platform. When using 'now()' in mule app, it consistently returns a time that is one hour different as Europe/Berlin time as I expected. Therefore, I made a change to explicitly request the time in the Europe/Berlin timezone. See below

var formattedCurrentTime= now() as String { format: "yyyy-MM-dd'T'HH:mm:ss", timezone: "Europe/Berlin" }

But it still return same result , Do you have any idea about it? PS: The problem is only on deployed Mule App at anypoint platform. With local system or on https://dataweave.mulesoft.com/learn/dataweave It works correctly

Any hints or ideas? thank you all (dear mule riders) in advance!

1

There are 1 answers

0
aled On

Mule applications deployed on CloudHub always use UTC as the timezone. Berlin timezone is UTC+1, which probably explains the difference. What you should do is to change the timezone of the date time returned by now() before formatting it to a string.

Example

%dw 2.0
output application/json
---
{
    now: now() as String { format: "yyyy-MM-dd'T'HH:mm:ss" },
    nowToBerlin: (now() >> "Europe/Berlin") as String { format: "yyyy-MM-dd'T'HH:mm:ss" }
}

Output:

{
  "now": "2023-12-26T19:18:51",
  "nowToBerlin": "2023-12-26T20:18:51"
}

For more information read: https://docs.mulesoft.com/dataweave/latest/dataweave-cookbook-change-time-zone