# Timestamps...... Sorry

**URL:** https://discourse.nodered.org/t/timestamps-sorry/7364
**Category:** General
**Created:** [29 January 2019 12:38 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364 "2019-01-29T12:38:45Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [29 January 2019 12:38 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/1 "2019-01-29T12:38:45Z")

</div>

I've been messing about with things and wanted a "human readable" time stamp on stuff.

I've seen reference to the `J: now()` thing which is handy to put in, as I just add a `change` node and set msg.time to `J: now()` and I get a nice time stamp.

What I didn't realise is it is Zulu time.

Yeah, there is the `simpletime` node. Bit of overkill I think.

I could use it. But I just want a quick and easy way to just time stamp a message for later diagnostic stuff, and I would prefer human readable.

Thanks in advance.  
(as you may have noticed: I'm back to the NR projects.)  
(It is just upsetting that as hard as I have tried: I've forgotten things since the last time.)

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [29 January 2019 12:51 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/2 "2019-01-29T12:51:33Z")

</div>

So to get to the point, you want a node that gives you a human readable date.

But not the `simpletime` node that reportedly does just that?

If a node that the author describes as "extremely lightweight" is overkill for your needs, can you describe why? As I imagine other nodes with the same functionality are likely to fail your criteria as well.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [29 January 2019 13:10 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/3 "2019-01-29T13:10:52Z")

</div>

OK, sorry.

I was reading on another thread that it wasn't.

I don't/didn't have it installed so couldn't comment.

(See new post on the install of simpletime)

So the `J: now()` is strictly Zulu time?

Ok.

---

<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: [29 January 2019 13:16 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/4 "2019-01-29T13:16:25Z")

</div>

You should really be doing as much date/time processing as possible in UTC/Zulu/GMT since it avoids the **many** issues that local times bring with them. Such as daylight saving switches for example.

It really does make life a lot easier if you do your processing in UTC then convert to local time on display.

Also note that node-red-contrib-moment contains a humanizer node as well as the main moment node which will give you human readable output. While this is certainly not lightweight under the covers, it is certainly simple from a flow designers perspective.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [29 January 2019 13:23 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/5 "2019-01-29T13:23:16Z")

</div>

This is only for short term debugging.

There are a few more gremlins in the system and I want to stamp the messages with a human readable time stamp so I can see when these erroneous things are happening.

I hope they life of this bit of the flow is less than a month.

This is a **very cut down** example of the flow: Suffice to get the idea.

```auto
[{"id":"ea68388a.cb83","type":"inject","z":"baf80d2f.6bd538","name":"","topic":"temp/external","payload":"test","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":3850,"wires":[["6247db4b.10bcbc","8f4a7a76.a39ee"]]},{"id":"8f4a7a76.a39ee","type":"change","z":"baf80d2f.6bd538","name":"Time","rules":[{"t":"set","p":"time","pt":"msg","to":"$now()","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":3850,"wires":[["d6ba8a8.e508878"]]},{"id":"d6ba8a8.e508878","type":"function","z":"baf80d2f.6bd538","name":"","func":"var topic = msg.topic;\nmsg.otopic = topic;\nvar res = topic.replace(\"/\", \"-\");\n\nmsg.topic = res;\n\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":3850,"wires":[["43cf92ab.284474"]]},{"id":"43cf92ab.284474","type":"debug","z":"baf80d2f.6bd538","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","x":690,"y":3850,"wires":[]}]

```

00:23 local time.

System shutting down for "today".

---

<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: [29 January 2019 13:26 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/6 "2019-01-29T13:26:36Z")

</div>

In programming, it is all to often the "simple" things (for users) that are the hardest to program!

---

<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: [29 January 2019 15:44 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/7 "2019-01-29T15:44:24Z")

</div>

So are you ok now or do you need further help? If you need further help what are you currently getting in the debug and what do you want to see?

---

<div class="post-metadata">

### Author: ![JayDickson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jaydickson/32/90592_2.png) [@JayDickson](https://discourse.nodered.org/u/JayDickson)
#### Post date: [29 January 2019 15:51 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/8 "2019-01-29T15:51:21Z")

</div>

Seconding the recommendation to play with the [moment](https://www.npmjs.com/package/node-red-contrib-moment) node (to hopefully counter any impression of bias on the part of other posters... for... reasons... 😉) If there was ever a candidate for a contrib node to be rolled up into the core set, I'd argue for moment and dashboard.

---

<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: [29 January 2019 16:01 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/9 "2019-01-29T16:01:06Z")

</div>

> [@JayDickson](#):
>
> If there was ever a candidate for a contrib node to be rolled up into the core set, I'd argue for moment and dashboard.

:shudders: Nooo! 😉

Quite apart from the fact that they are managed by different people :cough: moment would have to be combined with uibuilder if anything!

They are each complex enough to be kept separate though thanks.

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [29 January 2019 18:27 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/10 "2019-01-29T18:27:33Z")

</div>

> [@Trying\_to\_learn](#):
>
> So the `J: now()` is strictly Zulu time?

I assume that `J:` here means JSONata. According to the documentation, the `$now()` function supports optional arguments for formatting and timezone, but I have not been able to get this working. Perhaps we are dealing with an early/partial version, or I am messing up.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [29 January 2019 20:05 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/11 "2019-01-29T20:05:37Z")

</div>

Morning all.

(6 hours of sleep later)

Ok. moment will be looked at.

> [@drmibell](#):
>
> the `$now()` function supports optional arguments for formatting and timezone, but I have not been able to get this working. Perhaps we are dealing with an early/partial version, or I am messing up.

Yes, you are correct.

If you look in the small flow I posted it will show you how to do it.

I didn't know of the options.

I was searching for how to get the time and found a few threads.  
Someone said use the `J: now()` to do it. So I tried it and it worked.

Yeah, shame on me. Should 'a' looked a bit harder for docs on extras stuff you can stick on it.

---

<div class="post-metadata">

### Author: ![hugobox](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hugobox/32/2948_2.png) [@hugobox](https://discourse.nodered.org/u/hugobox)
#### Post date: [29 January 2019 20:33 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/12 "2019-01-29T20:33:05Z")

</div>

To timestamp a message for humans you could alternatively use a function node with:

```auto
msg.time = new Date().toLocaleString()
return msg;
```

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [29 January 2019 20:34 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/13 "2019-01-29T20:34:45Z")

</div>

I am also looking for where the "options" for the `J: $now()` (forgot the $ in previous posts - sorry.) but that looks just as easy.

Appreciated.

Oh, not to be picky but.....

> [@hugobox](#):
>
> msg.time = new Date().toLocaleString()

That needs a terminating `;` - yeah? 😉

---

<div class="post-metadata">

### Author: ![hugobox](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hugobox/32/2948_2.png) [@hugobox](https://discourse.nodered.org/u/hugobox)
#### Post date: [29 January 2019 20:41 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/14 "2019-01-29T20:41:33Z")

</div>

Adding semicolons at the end of lines is optional most of the time as Javascript figures it out automagically!

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [29 January 2019 21:30 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/15 "2019-01-29T21:30:56Z")

</div>

Hopefully still on topic, the JSONata `$now` function does not behave the same way in the `change` node as in the exerciser on the [website](http://docs.jsonata.org/overview.html).

In the exerciser:  
$now() =\> "2019-01-29T21:10:52.783Z"  
$now('[H01]:[m01]:[s01] [z]', '-0500') =\> "16:09:44 GMT-05:00"

In the `change` node:  
$now() =\> "2019-01-29T21:10:52.783Z"  
$now('[H01]:[m01]:[s01] [z]', '-0500') =\> Invalid JSONata expression: Argument 1 of function "now" does not match function signature

I dimly remember an earlier discussion of which version of JSONata is used in NR and what limitations it has, but I can't find it. Can we get an update on this?

---

<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: [29 January 2019 21:37 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/16 "2019-01-29T21:37:37Z")

</div>

Node-RED 0.19.5 has JSONata 1.5.4

Node-RED 0.20.0-beta.4 has JSONata 1.6.4 (the latest at the time of writing)

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [29 January 2019 21:44 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/17 "2019-01-29T21:44:28Z")

</div>

Thanks!

I'll dig in and see if that explains anything. It's a good excuse to finally start playing with the beta.

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [29 January 2019 21:58 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/18 "2019-01-29T21:58:16Z")

</div>

A quick look at the changelog on GitHub says that this feature was introduced with v 1.6.1. Problem probably solved. Perhaps someone already running the beta could confirm.

---

<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: [29 January 2019 22:13 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/19 "2019-01-29T22:13:09Z")

</div>

Beta works fine

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [31 January 2019 16:11 UTC](https://discourse.nodered.org/t/timestamps-sorry/7364/20 "2019-01-31T16:11:16Z")

</div>

> [@Trying\_to\_learn](#):
>
> I've been messing about with things and wanted a "human readable" time stamp on stuff.

> [@Colin](#):
>
> If you need further help what are you currently getting in the debug and what do you want to see?

Others have already stated strongly that all processing should be done on GMT timestamps -- which is solid advice. Save the conversions to human-readable for the UI...

BUT, I'm thinking that some confusion (and complexity) could be avoided if the debug sidebar would show human readable timestamps using the \*browser's timezone", not Zulu time? Whether that is just another "setting" or one of the "modes" that would appear while toggling through the display in the sidebar, well that's another question...

Currently, when a timestamp is shown in debug and I click on it, the display cycles between:  
`1548949510139` - _internal timestamp_  
`2019-01-31T15:45:10.139Z` - _zulu time_  
`0x168a495d7fb` - _hexadecimal_

Maybe just add another for local (browser) time?

[Next page](https://discourse.nodered.org/t/timestamps-sorry/7364.md?page=2)
