Why is the time in the NR log not local time?

OSX: 10.13.6

When I start NR I notice that the time in the log looks to be UTC and not my local time. Is there a way to change it to show local time?

Here is a example:

Pauls-mini:~ Paul$ date
Sun Oct 21 06:38:35 EDT 2018
Pauls-mini:~ Paul$ node-red mudash.json
21 Oct 12:38:40 - [info]
Welcome to Node-RED

21 Oct 12:38:40 - [info] Node-RED version: v0.19.4
21 Oct 12:38:40 - [info] Node.js version: v8.9.4
21 Oct 12:38:40 - [info] Darwin 17.7.0 x64 LE
21 Oct 12:38:41 - [info] Loading palette nodes
21 Oct 12:38:41 - [warn] rpi-gpio : Raspberry Pi specific node set inactive

Hmmm... on my Pi the dates are the same:

pi@mqttpizw : ~ $ date
Sun Oct 21 07:03:10 EDT 2018
pi@mqttpizw : ~ $ node-red
21 Oct 07:03:25 - [info]
Welcome to Node-RED
21 Oct 07:03:25 - [info] Node-RED version: v0.18.7
21 Oct 07:03:25 - [info] Node.js version: v8.11.3
21 Oct 07:03:25 - [info] Linux 4.14.52+ arm LE

The reason is that system times should ALWAYS be in UTC not local time. This reduces any time processing issues. Only convert to local time on display.

On Linux systems - the system time will always be in UTC. You can set the timezone at the system level which will assist in conversions.


I think you have misinterpreted the question, the timestamps shown against messages in the node red log are normally in local time, on my systems anyway. In @zenofmud's they are in UTC. Could this be a Mac issue?

OK, from the command line, run date to see what timezone the system is using. The command cat /etc/timezone will also show you.

If the timezone is incorrect, run tzselect (not sure if that needs to be run as sudo) or, perhaps better, run sudo dpkg-reconfigure tzdata.

You might need to try several of these methods if your Mac doesn't use one of them. There are also other possibilities that you will need to look up.

If you look at the first post you will see that I did a 'date' right before runn NR - date shows the local date/time and NR shows the UTC date/time.

The second post shows running on a Pi where both 'date' and NR show the date/time as the local date/time

In addition my system log shows the local date/time.

It's something I'd never noticed before and wondered if there was a NR option to use the local date/time that I hadn't set on my Mac.

Is there a solution to this problem? I'm running NR on Raspberry Pi.
I'm in a +1 timezone:

pi@raspberrypi:~ $ date
Fri 18 Dec 10:26:28 CET 2020
pi@raspberrypi:~ $ cat /etc/timezone

Yet when I use Inject node and set it to run at 10:00, it will run at 11:00. When I send new Date() from Node-RED, i get UTC instead of local. How to make NR to use local time?

new Date() gives you the current time. For example 12:00 UTC is the same time as 13:00 UTC+1. It is the same time and that is what new Date() gives you. When you display it you can show it in whatever timezone you like, including the local timezone.

However the Inject node assumes that you are entering times in the local timezone so the symptom you describe is not as it should be. Are you running node-red in Docker? If so then I think you need to tell Docker what the local timezone is, but I don't know the details of how to do that.

Otherwise show us how you have configured the Inject node and tell us how you know what time it triggered at.

[Edit] I have just noticed the title of the thread. Show us a segment of the log that shows the problem.

1 Like

I'm not using Docker (it almost doesn't work on RPi 1B because of ARMv6). And I must admit that I ended up in this thread from Google and thought it's the same issue as mine though I'm focusing on NR editor and not the logs.

As for new Date(), when I run it locally in my browser, it returns local, not UTC. I need to call toUTCString() to get UTC, not local:

x = new Date()
Date Fri Dec 18 2020 11:27:17 GMT+0100 (czas środkowoeuropejski standardowy)
"Fri, 18 Dec 2020 10:27:17 GMT"

I would assume NR running on RPi should use the same date/timezone as date command is returning, not the UTC.

As for Inject node, I select Repeat at a specific time and have.. say 10:00. That flow sends a mail and Telegram chat. Both are sent at 11:00.

Here is simple test flow:

[{"id":"79ebeb20.476aa4","type":"inject","z":"4103e39d.49460c","name":"Set at 10:00, will be invoked at 11:00","props":[{"p":"payload"}],"repeat":"","crontab":"00 10 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":270,"y":340,"wires":[["54aa1cbf.4adfac"]]},{"id":"54aa1cbf.4adfac","type":"function","z":"4103e39d.49460c","name":"Sends new Date(), time will be in UTC, not local","func":"msg.payload = `Date: ${(new Date())}`;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":680,"y":340,"wires":[["968f63de.464fa","feb29d40.8a59d"]]},{"id":"feb29d40.8a59d","type":"debug","z":"4103e39d.49460c","name":"Here I send it via mail/Telegram","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1050,"y":340,"wires":[]}]

Debug response is "Date: Fri Dec 18 2020 10:33:56 GMT+0000 (Greenwich Mean Time)", I would expect it to be the same as date command, so:

pi@raspberrypi:~ $ date
Fri 18 Dec 11:35:07 CET 2020

So while formatting Date() can be done in function node (altough JS does not have nice tools for that, but anyway, this could be done), Inject node would require manual adjusting (2 times a year for DST probably), not a good solution.

Probably I should create new thread instead of hijacking this one - I just assume it's the same issue.

Not 100% certain what you mean here. But at a guess, nodejs runtime is not the same as a browers.
What node version do you have on the node-red server?

Are you sure of that? have you tested? I dont use fixed times on the inject.
What timezone and time does your node-red server have set (for the sake of clarity and other readers sake i will spell out the obvious - "your browser is often not the machine where node-red is running")

I dont know about that (never tested it) but the cron-plus node is aware of system time changes (including time corrections through NTP and DST changes) and adjusts its set schedules accordingly

I'm not saying NR runs on the browser. Well, it's Node-RED after all.
I use node v12.19.0
Anyway, I found out that JS when converting new Date() to a string does not use .toString() but .toISOString() so looks like this part is fine:

pi@raspberrypi:~ $ cat d.js
console.log(new Date().toString());
console.log(new Date());

pi@raspberrypi:~ $ node d.js
Fri Dec 18 2020 12:58:45 GMT+0100 (Central European Standard Time)

pi@raspberrypi:~ $ date
Fri 18 Dec 12:58:59 CET 2020

So looks like node.js is respecting local time and timezone settings and it's was my bad assumption about converting Date to string. I was mislead as JS in the browser behaves differently. However, problem with Inject node seems still valid.

Well, I wouldn't waste anyone's time if I haven't. See the simple example above for the explanation. I get all my notifications 1h later than set inside Inject nodes.

To make sure I just did another test. I setup two flows (as in the example), one for 12:05 and another for 13:05. At 13:05 I got notification from 12:05 flow.

You would be surprised (i find that to be the norm (users not checking - you and I are in a minority unfortunately) So if i assume you have done this & you hadn't - we'd both be wasting time). I am not trying to teach you to suck eggs - i just dont know your abilities - so I cover all bases & at the end of the day, I am only trying to assist in a detailed manner (no need to be defensive).

Are the server and your client on same timezone and have same time set? (I could probably work that out from your previous posts - but humour me :slight_smile: )

I did an experiment ...

  • I adjusted my timezone to GMT+1 (clock shows 13:21, actual time here 12:21).
  • Setup an inject for 13:22 (1 minute time)
  • It fired at 13:22

NOTE: in my case, this is not a Raspberry PI & server/client are same machine. I will try with a RPi to see how that performs.

PS, if the event time is critical to you, the inject is not your best choice. there is a thread floating around about how RPi doesnt have a RTC and if node-red is running before the clock syncs to NTP, the fired events occur at odd times. The cron-plus node takes care of that & auto corrects and set schedules.

1 Like

Sure, my defensive answer could be just not being native and super fluent in English.

Yes, both set as UTC+1 Poland time (no DST as we have winter now).
Time is not critical for those flows and I use it only in several places so I could just manually adjust them but I see this as a kind of a bug and would like to understand it and perhaps fix it.

I must admit that I haven't check the code for Inject node yet to see how it knows when to fire the event. This could shed some light on that matter.
Thanks for your time so far. I appreciate your help.

Here is my test:

Set at 12:05, invoked at 13:05 local time. Notice that payload is using (new Date()).toString() which return 12:05 so UTC while as posted in the previous post when I run (new Date()).toString() directly on RPi via node.js I get local 13:05. Something's fishy here :wink:

Certainly the Inject node should use server local time for knowing when to inject. If not then that is a bug.

Can you stop node red and restart it in a terminal and post the startup log here please. If you installed using the recommended script then you can do that using
Also check, having restarted, that the inject node is still not doing what it should. Do not change the Pi's time or timezone after restarting node-red.

I set PI to GMT+1 and PC to GMT+1

Set an inject to trigger at 14:37 - it correctly works for me.

What node-red version are you using?

Ok, I feel a bit ashamed that I haven't restarted NR before posting here. After restart it's picking proper time. In logs, in Inject node.. even new Date().toString() now returns the same value as simple new Date().
So I add restart NR before posting to forum to my future list regarding covering all bases :slight_smile:
I apologize for the fuss and thanks for the help on tracking the reason down.


This is caused by a known bug in the inject node. It does not notice if the system time is changed after node red is started. https://github.com/node-red/node-red/issues/1839

One solution is to use the cron-plus node instead, which does not suffer from the problem.

1 Like

In the latest nodered.service file there is a line you can uncomment to make it wait until it has a timesync... we don't enable it by default for obvious reasons... (like if you aren't on a network and never get time sync it won't ever start)...

1 Like

Looks like if you wait for multi-user.target, NTP should have updated if the Internet was available?