Change timezone from UTC to UTC 01:00

I have a small timezone problem. I would be very thankful if someone could help me. I have tried various time nodes to no avail. I cant get Luxon or moment.js to work in function node either.

Heres the problem:

I get data in wrong timezone. I need JSONata to add 1 hour like the format in orange text below. Red time is my input. Orange time should be output.

Orange time is what i need:

This is what i currently have in JSONata: (No transformation on time here)

How can i do this within JSONata change node(or in some other way)? I am thankful for all replies and help.

Welcome to the forum @orrinen

The times you show are the same time, displayed using a different timestamp. What do you want to do with it?

Also what timezone is the node red server and if you are using Docker, what timezone have you set the docker container to?

Thank you sir.

The first timestamp( in red) is from an API. That arrives in british time. I need to tranform it to norwegian time +01:00 hour. The timestamps look the same, since the only difference is in the hour 01:00 - 02:00 and Zulu - UTC +01:00

What are you going to do with the timestamp?
That is important in order to help you.

You didn't answer the question about the timesaving. Also tell us the timezone of the machine running the browser. The reason it is important is that the browser can automatically show the timestamp in is timezone.

The timestamp is an input for a function.

The timezone of the machine running is UTC 01:00 (norwegian time).

Can you feed it into a debug node and show us how it displays it. Is it a string or a JavaScript Date object?

Its in ISO format. As string i belive.

Ok. Was I said, the two timestamps in your first post are the same time, just formatted differently. You can convert the string to a Date using
const time = new Date(msg.payload[I].timestamp)
If your function expects a JavaScript Date then that should do you. If you're function needs it to be in the particular timezone then there is a Date function to do that. I am on my phone at the moment but if you look up JavaScript Date you should find out.

The Jsonata expression in a change node would be


with msg.payalod set to 20022-11-17T00:00:00.000Z
output is 2022-11-17T01:00:00+01:00

Thank you for the help so far both @Colin and @E1cid.
I will see what i can do to fix

Please also remember what you are looking at. If the output to debug has converted a JavaScript date object to an ISO8602 string as is standard for a JSON conversion, that output SHOULD always be in UTC because that's the standard.

So whatever you do, you need to convert to an alternative STRING format before display.

Ok. Looks like i got it fixed. Thanks for help @Colin, @E1cid and @TotallyInformation.
@E1cid suggestion got me through timezone hell, and into the promised lands of working code.
Some jsonata with moment.js was all that was needed.

For further reference with timezone change with moment in jsonata, here is the flow with JSONata in change node.

[{"id":"9586c7f692c0bf12","type":"tab","label":"JSONata Time Change","disabled":false,"info":"","env":[]},{"id":"c7851abbbae31948","type":"nordpool-api-plus","z":"9586c7f692c0bf12","name":"Nordpool ","area":"Oslo","currency":"NOK","x":460,"y":200,"wires":[["b8d0a5d9aaf6a51f"]]},{"id":"1b8826ae1415d367","type":"function","z":"9586c7f692c0bf12","name":"","func":"let today = new Date();\nlet tomorrow = today.setDate(today.getDate() + 1);\ = tomorrow\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":200,"wires":[["c7851abbbae31948"]]},{"id":"f840143380835f49","type":"inject","z":"9586c7f692c0bf12","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 23 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":200,"wires":[["1b8826ae1415d367"]]},{"id":"b8d0a5d9aaf6a51f","type":"change","z":"9586c7f692c0bf12","name":"JSONata","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t   \"priceData\":[\t       {\t           \"value\": msg.payload[0].price,\t           \"start\": $moment($$.msg.payload[0].timestamp).utcOffset(1).format()                 \t       },\t       {\t           \"value\": msg.payload[1].price,\t           \"start\": $moment($$.msg.payload[1].timestamp).utcOffset(1).format()                 \t       },\t       {\t           \"value\": msg.payload[2].price,\t           \"start\": $moment($$.msg.payload[2].timestamp).utcOffset(1).format()                  \t       },\t       {\t           \"value\": msg.payload[3].price,\t           \"start\": $moment($$.msg.payload[3].timestamp).utcOffset(1).format()       \t       },\t       {\t           \"value\": msg.payload[4].price,\t           \"start\": $moment($$.msg.payload[4].timestamp).utcOffset(1).format()         \t       },\t       {\t           \"value\": msg.payload[5].price,\t           \"start\": $moment($$.msg.payload[5].timestamp).utcOffset(1).format()                      \t       },\t       {\t           \"value\": msg.payload[6].price,\t           \"start\": $moment($$.msg.payload[6].timestamp).utcOffset(1).format()        \t       },\t       {\t           \"value\": msg.payload[7].price,\t           \"start\": $moment($$.msg.payload[7].timestamp).utcOffset(1).format()      \t       },\t       {\t           \"value\": msg.payload[8].price,\t           \"start\": $moment($$.msg.payload[8].timestamp).utcOffset(1).format()         \t       },\t       {\t           \"value\": msg.payload[9].price,\t           \"start\": $moment($$.msg.payload[9].timestamp).utcOffset(1).format()         \t       },\t       {\t           \"value\": msg.payload[10].price,\t           \"start\": $moment($$.msg.payload[10].timestamp).utcOffset(1).format()        \t       },\t       {\t           \"value\": msg.payload[11].price,\t           \"start\": $moment($$.msg.payload[11].timestamp).utcOffset(1).format()          \t       },\t       {\t           \"value\": msg.payload[12].price,\t           \"start\": $moment($$.msg.payload[12].timestamp).utcOffset(1).format()        \t       },\t       {\t           \"value\": msg.payload[13].price,\t           \"start\": $moment($$.msg.payload[13].timestamp).utcOffset(1).format()         \t       },\t       {\t           \"value\": msg.payload[14].price,\t           \"start\": $moment($$.msg.payload[14].timestamp).utcOffset(1).format()        \t       },\t       {\t           \"value\": msg.payload[15].price,\t           \"start\": $moment($$.msg.payload[15].timestamp).utcOffset(1).format()        \t       },\t       {\t           \"value\": msg.payload[16].price,\t           \"start\": $moment($$.msg.payload[16].timestamp).utcOffset(1).format()         \t       },\t       {\t           \"value\": msg.payload[17].price,\t           \"start\": $moment($$.msg.payload[17].timestamp).utcOffset(1).format()       \t       },\t       {\t           \"value\": msg.payload[18].price,\t           \"start\": $moment($$.msg.payload[18].timestamp).utcOffset(1).format()          \t       },\t       {\t           \"value\": msg.payload[19].price,\t           \"start\": $moment($$.msg.payload[19].timestamp).utcOffset(1).format()         \t       },\t       {\t           \"value\": msg.payload[20].price,\t           \"start\": $moment($$.msg.payload[20].timestamp).utcOffset(1).format()        \t       },\t       {\t           \"value\": msg.payload[21].price,\t           \"start\": $moment($$.msg.payload[21].timestamp).utcOffset(1).format()     \t       },\t       {\t           \"value\": msg.payload[22].price,\t           \"start\": $moment($$.msg.payload[22].timestamp).utcOffset(1).format()         \t       },\t       {\t           \"value\": msg.payload[23].price,\t           \"start\": $moment($$.msg.payload[23].timestamp).utcOffset(1).format()         \t       }    \t   ] \t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":200,"wires":[["04af4c51be691c05"]]},{"id":"04af4c51be691c05","type":"debug","z":"9586c7f692c0bf12","name":"debug 21","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":780,"y":200,"wires":[]}]

In JSONata you can use msg but it is a compatibility mode and can cause conflicts. You can apppend $$ or not, depending on context scope.

Your JSONata expression has duplication that is not needed, the following will accept any size array of objects.

[{"id":"f840143380835f49","type":"inject","z":"9586c7f692c0bf12","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":200,"wires":[["1b8826ae1415d367"]]},{"id":"1b8826ae1415d367","type":"function","z":"9586c7f692c0bf12","name":"","func":"let today = new Date();\nlet tomorrow = today.setDate(today.getDate() + 1);\ = tomorrow\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":200,"wires":[["c7851abbbae31948"]]},{"id":"c7851abbbae31948","type":"nordpool-api-plus","z":"9586c7f692c0bf12","name":"Nordpool ","area":"Oslo","currency":"NOK","x":480,"y":160,"wires":[["b8d0a5d9aaf6a51f"]]},{"id":"b8d0a5d9aaf6a51f","type":"change","z":"9586c7f692c0bf12","name":"JSONata","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t   \"priceData\":[\t       $$.payload{\t           \"value\": $.price,\t           \"start\": $moment($.timestamp).utcOffset(1).format()                 \t       }\t   ]\t}      ","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":200,"wires":[["04af4c51be691c05"]]},{"id":"04af4c51be691c05","type":"debug","z":"9586c7f692c0bf12","name":"debug 21","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":780,"y":200,"wires":[]}]


           "value": $.price,
           "start": $moment($.timestamp).utcOffset(1).format()                 

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