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

**URL:** <https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162>\
**Category:** General\
**Created:** [21 October 2018 10:53 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162 "2018-10-21T10:53:11Z")\
**Posts on this page:** 20\
**Page:** 1

<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:** [21 October 2018 10:53 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/1 "2018-10-21T10:53:12Z")

</div>

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
```

---

<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:** [21 October 2018 11:05 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/2 "2018-10-21T11:05:43Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [21 October 2018 12:49 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/3 "2018-10-21T12:49:49Z")

</div>

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.

---

<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:** [21 October 2018 13:05 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/4 "2018-10-21T13:05:39Z")

</div>

> [@TotallyInformation](#):
>
> The reason is that system times should **ALWAYS** be in UTC not local time.

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?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [21 October 2018 14:58 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/5 "2018-10-21T14:58:35Z")

</div>

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.

---

<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:** [21 October 2018 15:42 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/6 "2018-10-21T15:42:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Marooned](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marooned/32/2858_2.png) [@Marooned](https://discourse.nodered.org/u/Marooned)\
**Post date:** [18 December 2020 09:29 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/7 "2020-12-18T09:29:18Z")

</div>

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

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

```

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?

---

<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:** [18 December 2020 10:02 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/8 "2020-12-18T10:02:44Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![Marooned](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marooned/32/2858_2.png) [@Marooned](https://discourse.nodered.org/u/Marooned)\
**Post date:** [18 December 2020 10:40 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/9 "2020-12-18T10:40:50Z")

</div>

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:

```auto
x = new Date()
Date Fri Dec 18 2020 11:27:17 GMT+0100 (czas środkowoeuropejski standardowy)
x.toUTCString()
"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:

```auto
[{"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:

```auto
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.

---

<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:** [18 December 2020 11:36 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/10 "2020-12-18T11:36:32Z")

</div>

> [@Marooned](#):
>
> 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:

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?

> [@Marooned](#):
>
> 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.

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")

> [@Marooned](#):
>
> Inject node would require manual adjusting (2 times a year for DST probably), not a good solution.

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

---

<div class="post-metadata">

**Author:** ![Marooned](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marooned/32/2858_2.png) [@Marooned](https://discourse.nodered.org/u/Marooned)\
**Post date:** [18 December 2020 12:11 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/11 "2020-12-18T12:11:54Z")

</div>

> [@Steve-Mcl](#):
>
> 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?

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:

```auto
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)
2020-12-18T11:58:46.054Z

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](https://github.com/nodejs/node/issues/19480). However, problem with Inject node seems still valid.

> [@Steve-Mcl](#):
>
> Are you sure of that? have you tested?

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.

---

<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:** [18 December 2020 12:33 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/12 "2020-12-18T12:33:49Z")

</div>

> [@Marooned](#):
>
> Well, I wouldn't waste anyone's time if I haven't

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).

> [@Marooned](#):
>
> 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.

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 🙂 )

* * *

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/47838256f4d3e30537bf157cb6f79b5e95033893.png)

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.

---

<div class="post-metadata">

**Author:** ![Marooned](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marooned/32/2858_2.png) [@Marooned](https://discourse.nodered.org/u/Marooned)\
**Post date:** [18 December 2020 13:07 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/13 "2020-12-18T13:07:12Z")

</div>

> [@Steve-Mcl](#):
>
> I cover all bases

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

> [@Steve-Mcl](#):
>
> Are the server and your client on same timezone and have same time set?

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:

 ![obraz](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/2/022040f8e7241fed2b9155e7a410a1963b6ab5fe.png)  
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 😉

---

<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:** [18 December 2020 13:31 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/14 "2020-12-18T13:31:16Z")

</div>

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  
`node-red-stop`  
`node-red-start`  
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.

---

<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:** [18 December 2020 13:41 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/15 "2020-12-18T13:41:08Z")

</div>

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

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

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

What node-red version are you using?

---

<div class="post-metadata">

**Author:** ![Marooned](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marooned/32/2858_2.png) [@Marooned](https://discourse.nodered.org/u/Marooned)\
**Post date:** [18 December 2020 13:57 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/16 "2020-12-18T13:57:44Z")

</div>

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` 🙂  
I apologize for the fuss and thanks for the help on tracking the reason down.

---

<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:** [18 December 2020 14:02 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/17 "2020-12-18T14:02:06Z")

</div>



---

<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:** [18 December 2020 14:22 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/18 "2020-12-18T14:22:06Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [18 December 2020 14:49 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/19 "2020-12-18T14:49:41Z")

</div>

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)...

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [19 December 2020 00:07 UTC](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162/20 "2020-12-19T00:07:25Z")

</div>

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

[Next page](https://discourse.nodered.org/t/why-is-the-time-in-the-nr-log-not-local-time/4162.md?page=2)
