# UTC vs Local time - Inject Node 'at a specific time'

**URL:** <https://discourse.nodered.org/t/utc-vs-local-time-inject-node-at-a-specific-time/43903>\
**Category:** General\
**Created:** [9 April 2021 08:14 UTC](https://discourse.nodered.org/t/utc-vs-local-time-inject-node-at-a-specific-time/43903 "2021-04-09T08:14:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarkC](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/markc/32/37535_2.png) [@MarkC](https://discourse.nodered.org/u/MarkC)\
**Post date:** [9 April 2021 08:14 UTC](https://discourse.nodered.org/t/utc-vs-local-time-inject-node-at-a-specific-time/43903/1 "2021-04-09T08:14:32Z")

</div>

Hello,  
I have been through a number of old topics, but the 'correct' time behavior is not totally clear to me.

I am using NodeRED embedded into a device, and am having some difficulties with my logic since NodeRED seems to be using UTC time. And manually adjusting for the time difference is a real pain + the offset changes with daylight savings and depending on location, if I was to share my flow.

As a start, could someone please help me to confirm if:

1. The Inject Node 'at a specific time' function, **should** trigger based on Local or UTC Time?

2. The `new Date()` function **should** provide Local or UTC Time?

I really hope/expect that the answer to both of these 2 questions is 'Local Time', then I can highlight the issue and hopefully get it fixed.

Thanks in advance, Mark.

---

<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:** [9 April 2021 09:00 UTC](https://discourse.nodered.org/t/utc-vs-local-time-inject-node-at-a-specific-time/43903/2 "2021-04-09T09:00:42Z")

</div>

The inject node and `new Date()` with give you _the_ current time. There is only one current time, but there are multiple ways of displaying it. If for example we were to talk to each other on the phone we would be doing it at the same time, which might be 12:00 in my local time for me, 13:00 in your local time for you and is also 11:00 UTC, but all those are the same time. You can display it as an ISO format date, in which case it will have a time zone indicator on the end, probably Z, indicating that this is the current time shown in UTC, or you could use `toLocaleString()` which will display it in local time . If your device has the timezone set on it (assuming it knows about time zones) then an Inject node, or scheduling nodes such as cron-plus, will assume that the times you enter are in local time and will trigger at the appropriate local time.

---

<div class="post-metadata">

**Author:** ![MarkC](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/markc/32/37535_2.png) [@MarkC](https://discourse.nodered.org/u/MarkC)\
**Post date:** [9 April 2021 09:43 UTC](https://discourse.nodered.org/t/utc-vs-local-time-inject-node-at-a-specific-time/43903/3 "2021-04-09T09:43:01Z")

</div>

Hi Colin,  
Thanks for your response.

The device running NodeRED does have the local time set, but it might not be sharing/syncing that with NodeRED.

I have tried your suggestion:

```auto
var d = new Date();
var n = d.toLocaleString();

msg.payload = n
return msg;

```

But there is no change to the reported time - see screen image below (PS. 2nd log is without `toLocaleString()`), note that the debug time **is the correct local time** :  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/af266a13af0e6e592f1858278affcdf551444d8f.png)

Does this confirm there is a time sync issue on the device?

Also, what about the Inject node 'at a specific time' function, surely (if there are no issues) I don't need to manually calculate UTC time? How does this function work for everyone else?  
 ![B](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/3/5373c26f1015efd4cffeab19a4810a6acfe619e8.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [9 April 2021 10:09 UTC](https://discourse.nodered.org/t/utc-vs-local-time-inject-node-at-a-specific-time/43903/4 "2021-04-09T10:09:58Z")

</div>

> [@MarkC](#):
>
> Also, what about the Inject node 'at a specific time' function, surely (if there are no issues) I don't need to manually calculate UTC time? How does this function work for everyone else

So long as the server running node-red has the correct time and correct time zone it fires when it's supposed to / as set. E.g. set it for 7am, it fires at 7am.

---

<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:** [9 April 2021 10:15 UTC](https://discourse.nodered.org/t/utc-vs-local-time-inject-node-at-a-specific-time/43903/5 "2021-04-09T10:15:06Z")

</div>

That suggests the timezone that node-red is seeing is not correct. What device is it, how have you installed node-red and how do you know the timezone and date are set correctly?

Just a guess, but if you have installed a Docker node-red image then you have to set the timezone in the docker container.

---

<div class="post-metadata">

**Author:** ![MarkC](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/markc/32/37535_2.png) [@MarkC](https://discourse.nodered.org/u/MarkC)\
**Post date:** [9 April 2021 10:30 UTC](https://discourse.nodered.org/t/utc-vs-local-time-inject-node-at-a-specific-time/43903/6 "2021-04-09T10:30:41Z")

</div>

Thank you very much both, I think that confirms what I wanted to know.

It is a Victron 'GX device', which is a basically communication/control hub for their energy systems. 'Large image' firmware with NodeRED embedded is still in beta at the moment, so I will highlight this issue.

I know that the local time is set because I set it and also checked it. Also all other functions use the correct local time. I guess that it's just not being synced.

---

<div class="post-metadata">

**Author:** ![MarkC](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/markc/32/37535_2.png) [@MarkC](https://discourse.nodered.org/u/MarkC)\
**Post date:** [9 April 2021 10:36 UTC](https://discourse.nodered.org/t/utc-vs-local-time-inject-node-at-a-specific-time/43903/7 "2021-04-09T10:36:47Z")

</div>

One more question/confusing thing I noticed - when I feed raw data into a Dashboard line chart, the timestamps automatically added to the linechart are correct (in local time).

How is this possible if there is a time zone sync issue - is that time (on the chart) sourced from elsewhere?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [9 April 2021 10:52 UTC](https://discourse.nodered.org/t/utc-vs-local-time-inject-node-at-a-specific-time/43903/8 "2021-04-09T10:52:55Z")

</div>

the chart is client side (where your browser is) & it knows from your settings what time zone it is for your browser.

---

<div class="post-metadata">

**Author:** ![MarkC](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/markc/32/37535_2.png) [@MarkC](https://discourse.nodered.org/u/MarkC)\
**Post date:** [9 April 2021 11:03 UTC](https://discourse.nodered.org/t/utc-vs-local-time-inject-node-at-a-specific-time/43903/9 "2021-04-09T11:03:57Z")

</div>

Ok makes sense, thank you for confirming that Steve.

---

<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:** [23 April 2021 11:03 UTC](https://discourse.nodered.org/t/utc-vs-local-time-inject-node-at-a-specific-time/43903/10 "2021-04-23T11:03:59Z")

</div>

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