Wrong timezone in Node-RED

It seems my Node-RED is 2 hours off.

This is the output of an inject node directly connected to a debug node, notice the timestamp of the debug node is correct, but the string inside is 2 hours off:

debug

I run Node-RED in Docker, with the environment variable "TZ" set correctly, and this is the output of the date command both inside the Docker container and on the host machine:

Docker:
docker

Host:
host

How do I fix this?

You are receiving the timestamp in UTC you can format it for your time zone.
e.g.

[{"id":"451d767d.1de568","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":4180,"wires":[["24f0cea0.ec617a"]]},{"id":"24f0cea0.ec617a","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$moment($$.payload).tz(\"Europe/Berlin\").format()","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":4220,"wires":[["2d2a3654.07f15a"]]},{"id":"2d2a3654.07f15a","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":500,"y":4180,"wires":[]}]

Jsonata expression

$moment($$.payload).tz("Europe/Berlin").format()

Or you can use "CET" as timezone in expression

The string denotes Z which is Zulu time = UTC

Thank you!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.