# Wrong Timezone in NR - 2 hours to early

**URL:** https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979
**Category:** General
**Tags:** function-node
**Created:** [27 March 2023 08:59 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979 "2023-03-27T08:59:28Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)
#### Post date: [27 March 2023 08:59 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/1 "2023-03-27T08:59:28Z")

</div>

Hi,

I just found out, that my NR is showing the wrong timezone.

Although my server is using CEST and the right time ...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/c/0c90e8285503e20d2e5eacee428840b53dc14a5e.png)

... if I use this function in NR

`msg.payload = new Date().toISOString();`

I get this as a result:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/f/1f74d990efb52e8e57c394c92e4ca47e1f683873.png)

Unfortunately it is 2 hours too early and I have no idea where it comes from.

Any ideas ?

BR  
G

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [27 March 2023 09:10 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/2 "2023-03-27T09:10:37Z")

</div>

Hi @Gawan

That is correct `toISOString()` will report in `UTC`.  
CEST is +2 hours

---

<div class="post-metadata">

### Author: ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)
#### Post date: [27 March 2023 09:13 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/3 "2023-03-27T09:13:10Z")

</div>

what else should I use ?

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [27 March 2023 09:19 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/4 "2023-03-27T09:19:15Z")

</div>

You can use a `change` node, to set the `payload` to below.  
this will retain the offset I believe

Use the `expression` type in the dropdown

`$moment().toISOString(true)`

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/b/4b0ff979e114610798af2219193bbe35c5ee1e1c.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: [27 March 2023 09:28 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/5 "2023-03-27T09:28:17Z")

</div>

What do you want to do with the time? The time in the debug node is correct.

---

<div class="post-metadata">

### Author: ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)
#### Post date: [27 March 2023 09:31 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/6 "2023-03-27T09:31:15Z")

</div>

I want to show the time in a graph and people are complaining if it says "08:50" when it is "10:50" in reality 🙂

---

<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: [27 March 2023 09:33 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/7 "2023-03-27T09:33:38Z")

</div>

Have are you displaying it in the graph?

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [27 March 2023 09:45 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/8 "2023-03-27T09:45:01Z")

</div>

> [@Colin](#):
>
> The time in the debug node is correct.

Interestingly, the time format in the debug panel depends on debug node settings.

 ![Untitled 7](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/11e4502e00023f906426dd6df9288bc47485b3bb.jpeg)

> [@Gawan](#):
>
> people are complaining if it says "08:50" when it is "10:50" in reality

Are these people in the same timezone as the Node-red machine, ie CEST?

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [27 March 2023 09:50 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/9 "2023-03-27T09:50:16Z")

</div>

If you wanted to do this in a `function` node only.  
This will increase **your** localtime by 2 hours, before `ISOString()` reduces it according to the offset

```auto
const currentTime = new Date().getTime();
const date = new Date(currentTime + 2 * 60 * 60 * 1000);
msg.payload = date.toISOString();
return msg

```

there are also `moment` nodes one can install.

---

<div class="post-metadata">

### Author: ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)
#### Post date: [27 March 2023 09:57 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/10 "2023-03-27T09:57:52Z")

</div>

Yes, all people are sitting in the same timeszone as the server - CEST

I do not want to add static 2 hours to the timestamp - I want the timestamp to adapt to daylight savings.

Isn't there any functionality showing the right "Local time" ?

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [27 March 2023 10:04 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/11 "2023-03-27T10:04:07Z")

</div>

I think you need to show us a screen capture of the graph (showing the 2 hour problem) and an export of the graph UI node & nodes that feed it data points.

---

<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: [27 March 2023 10:04 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/12 "2023-03-27T10:04:25Z")

</div>

Set the chart to UTC.  
then it will display your UTC ISO timestamps

 ![chrome_screenshot_1679911874182](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/8/88a43251ac75bd1b18210788e72fd240bc95d926.jpeg)  
Data

```auto
[{"data":[[{"x":"2023-03-27T10:50:40.000Z","y":1},{"x":"2023-03-27T11:50:40.000Z","y":2},{"x":"2023-03-27T12:50:40.000Z","y":1},{"x":"2023-03-27T13:50:40.000Z","y":2}]],"series":["a"]}]

```

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [27 March 2023 10:08 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/13 "2023-03-27T10:08:13Z")

</div>

Hi @Gawan

As noted above, the function `toISOString()` always returns the time in `UTC`.

If you want it in the local time you can use: `toLocaleString()` or just `toString()`

Lots of details of the options available in the MDN docs: [Date.prototype.toLocaleString() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)

---

<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: [27 March 2023 10:29 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/14 "2023-03-27T10:29:46Z")

</div>

You need to tell us what sort of chart it is. If it is the dashboard chart it should automatically show the time in the time zone of the machine running the browser.  
If it isn't a dashboard chart what is it and how to you give it the timestamps.

---

<div class="post-metadata">

### Author: ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)
#### Post date: [27 March 2023 13:09 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/15 "2023-03-27T13:09:00Z")

</div>

I just tried all three of them, but result is always the same .... wrong

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/e/8ef5b96810fe6838283e4d7a0c6c43d7a64d6c97.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: [27 March 2023 13:46 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/16 "2023-03-27T13:46:13Z")

</div>

Are you running node red in Docker or HA or something else other than a native install

---

<div class="post-metadata">

### Author: ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)
#### Post date: [27 March 2023 19:21 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/17 "2023-03-27T19:21:12Z")

</div>

Try

```auto
const date = new Date('2023-03-27T10:50:40.000Z')

const options = {
    year: "numeric",
    month: "numeric",
    day: "numeric",
    hour: "numeric",
    minute: "numeric",
    second: "numeric",
    hour12: false,
    timeZone: "Europe/Warsaw",
}

msg.payload = Intl.DateTimeFormat('default', options).format(date)

```

The time zone was a CEST time zone chosen at random so set to whatever it should be.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [27 March 2023 23:00 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/18 "2023-03-27T23:00:22Z")

</div>

> [@Gawan](#):
>
> just tried all three of them, but result is always the same .... wrong
> 
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/e/8ef5b96810fe6838283e4d7a0c6c43d7a64d6c97.png)

I think this demonstrates that the timezone setting on your Node-red server is GMT, even though your **date** command shows CEST?

What does the **timedatectl** command show?  
What about **ls -l /etc/localtime**?

---

<div class="post-metadata">

### Author: ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)
#### Post date: [28 March 2023 05:14 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/19 "2023-03-28T05:14:45Z")

</div>

I am using 1 server with 20 node-red instances in a docker containers

the server as such is running on CEST  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/8/38faeb1629d1bf738deb45772da1fba0270496b0.png)

Timezone is Europe/Vienna

But I do not know if the container files are using different timezones - I do not know how to verify / change this ?  
It it even possible ?

---

<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: [28 March 2023 06:01 UTC](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979/20 "2023-03-28T06:01:44Z")

</div>

> [@Gawan](#):
>
> I do not know if the container files are using different timezones - I do not know how to verify / change this ?  
> It it even possible ?

Almost certainly that is the problem. You need to set the container to use the host timezone. I don't use docker but I am sure that a search engine will tell you how.

[Next page](https://discourse.nodered.org/t/wrong-timezone-in-nr-2-hours-to-early/76979.md?page=2)
