# Timestamps under a node when activated seem to be stuck in GMT

**URL:** <https://discourse.nodered.org/t/timestamps-under-a-node-when-activated-seem-to-be-stuck-in-gmt/10374>\
**Category:** General\
**Created:** [20 April 2019 07:50 UTC](https://discourse.nodered.org/t/timestamps-under-a-node-when-activated-seem-to-be-stuck-in-gmt/10374 "2019-04-20T07:50:09Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonk83](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/simonk83/32/7651_2.png) [@simonk83](https://discourse.nodered.org/u/simonk83)\
**Post date:** [20 April 2019 07:50 UTC](https://discourse.nodered.org/t/timestamps-under-a-node-when-activated-seem-to-be-stuck-in-gmt/10374/1 "2019-04-20T07:50:09Z")

</div>

I'm running the official docker in a VM, and have `- /etc/localtime:/etc/localtime:ro` set, but also added `environment: - TZ=Australia/Melbourne` just to try and rule that out (didn't help). I also run HassIO on another VM with the same parameters set. On both VM's, checking the date in the terminal returns the correct time and timezone, and exec'ing into the docker containers and checking the date is also correct, so it doesn't appear to be an issue at my end (though it still could be something else I suppose).

Debug timestamps in Node-RED are correct, it only seems to happen, as far as I can tell, when interacting with Homeassistant nodes.

Has anyone else seen this and know how to fix it? I imagine it'll be an issue if I try and do any time based automations...

---

<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:** [20 April 2019 08:18 UTC](https://discourse.nodered.org/t/timestamps-under-a-node-when-activated-seem-to-be-stuck-in-gmt/10374/2 "2019-04-20T08:18:46Z")

</div>

What do you mean by "Timestamps under a node"? Is it some particular node?

---

<div class="post-metadata">

**Author:** ![simonk83](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/simonk83/32/7651_2.png) [@simonk83](https://discourse.nodered.org/u/simonk83)\
**Post date:** [20 April 2019 08:22 UTC](https://discourse.nodered.org/t/timestamps-under-a-node-when-activated-seem-to-be-stuck-in-gmt/10374/3 "2019-04-20T08:22:25Z")

</div>

Yep I _think_ it only happens with HomeAssistant nodes. eg:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/433ee481fdb01e1eb7b18fcae5ffdb409bffacc5.png)

Those times are all GMT, I'm in AEST.

---

<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:** [20 April 2019 08:23 UTC](https://discourse.nodered.org/t/timestamps-under-a-node-when-activated-seem-to-be-stuck-in-gmt/10374/4 "2019-04-20T08:23:43Z")

</div>

That will be a specific issue with those nodes. They are responsible for providing the text that gets displayed. I suggest raising an issue against them so their maintainer can fix it.

---

<div class="post-metadata">

**Author:** ![simonk83](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/simonk83/32/7651_2.png) [@simonk83](https://discourse.nodered.org/u/simonk83)\
**Post date:** [20 April 2019 08:31 UTC](https://discourse.nodered.org/t/timestamps-under-a-node-when-activated-seem-to-be-stuck-in-gmt/10374/5 "2019-04-20T08:31:42Z")

</div>

No probs, I'll do that thanks 🙂

By the way Nick, bloody great job with this. I've only been playing around with it for a week but I'm super impressed. Not just by the functionality, but also the polish and the user friendliness.

---

<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:** [20 April 2019 10:04 UTC](https://discourse.nodered.org/t/timestamps-under-a-node-when-activated-seem-to-be-stuck-in-gmt/10374/6 "2019-04-20T10:04:31Z")

</div>

You can confirm the locale that the node red server is set to using this flow. The Debug node should show the local time in the browser, the warn statements in the function should show the timezone offset and the local time in the server.

```auto
[{"id":"1d778363.059135","type":"debug","z":"d7ff0732.2f81d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":525.5,"y":322,"wires":[]},{"id":"98c9671.b2fec98","type":"inject","z":"d7ff0732.2f81d8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":184,"y":319,"wires":[["f2045e49.17b4e"]]},{"id":"f2045e49.17b4e","type":"function","z":"d7ff0732.2f81d8","name":"Date","func":"msg.payload = new Date()\nnode.warn(\"Timezone offset in server: \" + msg.payload.getTimezoneOffset())\nnode.warn(\"Local time in server: \" + msg.payload.toLocaleString())\nreturn msg;","outputs":1,"noerr":0,"x":346.5,"y":318,"wires":[["1d778363.059135"]]}]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 April 2019 10:46 UTC](https://discourse.nodered.org/t/timestamps-under-a-node-when-activated-seem-to-be-stuck-in-gmt/10374/7 "2019-04-20T10:46:59Z")

</div>

@Colin odd, when I run your flow I get:

```auto
4/20/2019, 6:39:45 AM[node: Date](http://localhost:1880/#)function : (warn)
"Timezone offset in server: -120"
4/20/2019, 6:39:45 AM[node: Date](http://localhost:1880/#)function : (warn)
"Local time in server: 4/20/2019, 12:39:45 PM"
4/20/2019, 6:39:45 AM[node: e2356a6d.e0a7b8](http://localhost:1880/#)msg.payload : Date
"Sat Apr 20 2019 12:39:45 GMT+0200 (Central European Summer Time)" 

```

Yet if I go to [https://www.w3schools.com/jsref/jsref\_tolocalestring.asp](https://www.w3schools.com/jsref/jsref_tolocalestring.asp) I get the correct locale time:

 ![58%20AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/14a441ba7ff6018d9e24667ed733b25ac7cb23ef.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:** [20 April 2019 11:27 UTC](https://discourse.nodered.org/t/timestamps-under-a-node-when-activated-seem-to-be-stuck-in-gmt/10374/8 "2019-04-20T11:27:41Z")

</div>

Methinks the clock is wrong on your node red machine.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 April 2019 11:35 UTC](https://discourse.nodered.org/t/timestamps-under-a-node-when-activated-seem-to-be-stuck-in-gmt/10374/9 "2019-04-20T11:35:25Z")

</div>

browser and NR running on same machine (macOS 10.13.6)

---

<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:** [20 April 2019 12:28 UTC](https://discourse.nodered.org/t/timestamps-under-a-node-when-activated-seem-to-be-stuck-in-gmt/10374/10 "2019-04-20T12:28:12Z")

</div>

Is node-red running in a container of some sort?  
What is the correct timezone for where you are?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 April 2019 12:37 UTC](https://discourse.nodered.org/t/timestamps-under-a-node-when-activated-seem-to-be-stuck-in-gmt/10374/11 "2019-04-20T12:37:25Z")

</div>

I run NR from the terminal (i.e. node-red test.json)  
correct time zone is america/New York

---

<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:** [20 April 2019 12:49 UTC](https://discourse.nodered.org/t/timestamps-under-a-node-when-activated-seem-to-be-stuck-in-gmt/10374/12 "2019-04-20T12:49:48Z")

</div>

Just thought, is this running on Windows?  
If you try, in the flow, `toUTCString()` does it give you correct UTC time?  
It seems that node thinks it is UTC+2. If you _are_ on Windows then perhaps node needs to be told what the TZ is.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 April 2019 13:31 UTC](https://discourse.nodered.org/t/timestamps-under-a-node-when-activated-seem-to-be-stuck-in-gmt/10374/13 "2019-04-20T13:31:28Z")

</div>

runnng on a Mac  
here is the debug with UTC added:  
 ![47%20AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0962d62e003eebc2a29c00703616cfd727868851.png)  
and I grabbed the code from w3schools

```auto
<!DOCTYPE html>
<html>
<body>

<p>Click the button to display the date and time as a string.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
  var d = new Date();
  var n = d.toLocaleString();
  document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

```

Stored it on my machine and run it and this is the result:  
 ![25%20AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a3f9e300108f2e4a7f737d6c858763fccd53e49a.png)

Crazy isn't it.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 April 2019 13:41 UTC](https://discourse.nodered.org/t/timestamps-under-a-node-when-activated-seem-to-be-stuck-in-gmt/10374/14 "2019-04-20T13:41:36Z")

</div>

So it must be something about the mac. i just ran the flow on one of my Pi's nd it looks correct:  
 ![04%20AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0d5afd6e26e58752d3a04a1a95b056643f62276a.png)

Hmmmm

---

<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:** [20 April 2019 14:47 UTC](https://discourse.nodered.org/t/timestamps-under-a-node-when-activated-seem-to-be-stuck-in-gmt/10374/15 "2019-04-20T14:47:32Z")

</div>

Node is using the wrong time zone. When you run the javascript direct in the browser it is ok, it is only when node runs it (via node-red) that it is wrong.
