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

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.

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.

1 Like

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:

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

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

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.

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.

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.

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?

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

Ok makes sense, thank you for confirming that Steve.

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