# Change timezone from UTC to UTC 01:00

**URL:** <https://discourse.nodered.org/t/change-timezone-from-utc-to-utc-01-00/70709>\
**Category:** General\
**Created:** [16 November 2022 12:26 UTC](https://discourse.nodered.org/t/change-timezone-from-utc-to-utc-01-00/70709 "2022-11-16T12:26:59Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![orrinen](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/orrinen/32/81311_2.png) [@orrinen](https://discourse.nodered.org/u/orrinen)\
**Post date:** [16 November 2022 12:26 UTC](https://discourse.nodered.org/t/change-timezone-from-utc-to-utc-01-00/70709/1 "2022-11-16T12:26:59Z")

</div>

Hello.  
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.** _  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/d/9de5d686aa7bf937bc0474a4257e1a3b563c9809.png)

Orange time is what i need:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/2/f2cf24173ad690af9a193985ac6461463b1d418d.png)

**This is what i currently have in JSONata:** (No transformation on time here)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/3/b331f45525ca2a085f8702b61cfa523b9323850a.png)

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 November 2022 12:47 UTC](https://discourse.nodered.org/t/change-timezone-from-utc-to-utc-01-00/70709/2 "2022-11-16T12:47:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![orrinen](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/orrinen/32/81311_2.png) [@orrinen](https://discourse.nodered.org/u/orrinen)\
**Post date:** [16 November 2022 12:52 UTC](https://discourse.nodered.org/t/change-timezone-from-utc-to-utc-01-00/70709/3 "2022-11-16T12:52:34Z")

</div>

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_

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 November 2022 13:08 UTC](https://discourse.nodered.org/t/change-timezone-from-utc-to-utc-01-00/70709/4 "2022-11-16T13:08:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![orrinen](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/orrinen/32/81311_2.png) [@orrinen](https://discourse.nodered.org/u/orrinen)\
**Post date:** [16 November 2022 13:11 UTC](https://discourse.nodered.org/t/change-timezone-from-utc-to-utc-01-00/70709/5 "2022-11-16T13:11:57Z")

</div>

The timestamp is an input for a function.

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 November 2022 13:17 UTC](https://discourse.nodered.org/t/change-timezone-from-utc-to-utc-01-00/70709/6 "2022-11-16T13:17:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![orrinen](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/orrinen/32/81311_2.png) [@orrinen](https://discourse.nodered.org/u/orrinen)\
**Post date:** [16 November 2022 13:23 UTC](https://discourse.nodered.org/t/change-timezone-from-utc-to-utc-01-00/70709/7 "2022-11-16T13:23:12Z")

</div>

Its in ISO format. As string i belive.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/5/25a158036e261b5e94e3a51e35803d0d180410af.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 November 2022 13:30 UTC](https://discourse.nodered.org/t/change-timezone-from-utc-to-utc-01-00/70709/8 "2022-11-16T13:30:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [16 November 2022 13:57 UTC](https://discourse.nodered.org/t/change-timezone-from-utc-to-utc-01-00/70709/9 "2022-11-16T13:57:52Z")

</div>

The Jsonata expression in a change node would be

```auto
$moment($$.payload).utcOffset(1).format()

```

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

---

<div class="post-metadata">

**Author:** ![orrinen](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/orrinen/32/81311_2.png) [@orrinen](https://discourse.nodered.org/u/orrinen)\
**Post date:** [16 November 2022 14:07 UTC](https://discourse.nodered.org/t/change-timezone-from-utc-to-utc-01-00/70709/10 "2022-11-16T14:07:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [16 November 2022 14:13 UTC](https://discourse.nodered.org/t/change-timezone-from-utc-to-utc-01-00/70709/11 "2022-11-16T14:13:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![orrinen](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/orrinen/32/81311_2.png) [@orrinen](https://discourse.nodered.org/u/orrinen)\
**Post date:** [16 November 2022 14:33 UTC](https://discourse.nodered.org/t/change-timezone-from-utc-to-utc-01-00/70709/12 "2022-11-16T14:33:17Z")

</div>

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.

```auto
[{"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);\nmsg.date = 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":[]}]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [16 November 2022 14:56 UTC](https://discourse.nodered.org/t/change-timezone-from-utc-to-utc-01-00/70709/13 "2022-11-16T14:56:15Z")

</div>

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.

```auto
[{"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);\nmsg.date = 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":[]}]

```

expression

```auto
{
   "priceData":[
       $$.payload.{
           "value": $.price,
           "start": $moment($.timestamp).utcOffset(1).format()                 
       }
   ]
}      

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [30 November 2022 14:57 UTC](https://discourse.nodered.org/t/change-timezone-from-utc-to-utc-01-00/70709/14 "2022-11-30T14:57:03Z")

</div>

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