Adding The System Time for a Timestamp

564 views
Skip to first unread message

acestu

unread,
Oct 20, 2016, 3:46:12 PM10/20/16
to Node-RED
Hi,

I have a set of gauges in dashbord but I need to put the time that the gauge is updated underneath, I have a ui template that will put the data below the gauge but I just want to put a time the same as the Pi system time, if I use:

msg.payload = new Date().toString();
return msg;

It returns allsorts of text ie (UTC) etc, etc, and it just dosen't fit into the ui, it has a scroll bar, any help appreciated.

Thanks
Stuart

Nicholas O'Leary

unread,
Oct 20, 2016, 3:53:45 PM10/20/16
to Node-RED Mailing List

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/2f3e5276-168c-4533-b53d-76727af0453f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mark Setrem

unread,
Oct 20, 2016, 3:58:19 PM10/20/16
to Node-RED

A quick google for "How to format a JavaScript time" should give you enough info to format the date/time how you wish, which will hopefully then fit.




acestu

unread,
Oct 20, 2016, 4:06:39 PM10/20/16
to Node-RED
Thanks guys I will have a look at this now

Stuart

Mike Bell

unread,
Oct 20, 2016, 5:34:51 PM10/20/16
to Node-RED
Stuart,

I have solved similar problems using the NR moment node (node-red-contrib-moment) to format date/time strings for the dashboard. It gives you access to the formatting capabilities of moment.js. Depending on the structure of your flow, it might be easier than writing javascript for a function node.

Mike

acestu

unread,
Oct 21, 2016, 1:39:23 PM10/21/16
to Node-RED
Hi Mike, yes i stumbled on the moments node in the library, it's just a matter of working out how to use it lol, I would of thought somebody would of come up with a node for this by now.

thanks
Stuart

On Thursday, October 20, 2016 at 8:46:12 PM UTC+1, acestu wrote:

Mike Bell

unread,
Oct 21, 2016, 2:41:36 PM10/21/16
to Node-RED
Stuart,

As the contributor of the moment node (Julian Knight) was kind enough to point out to me, full documentation of moment.js is available at momentjs.com. In particular, you might want to look at http://momentjs.com/docs/#/displaying/.

Mike

acestu

unread,
Oct 21, 2016, 2:52:51 PM10/21/16
to Node-RED
Hi Mike,

Yes I found the documentation, I am going through it all now, what I meant was it all looks a bit daunting as I am not a coder or computer wizz, i am just learning how to make a home automation system.

Thanks
Stuart

On Thursday, October 20, 2016 at 8:46:12 PM UTC+1, acestu wrote:

Mike Bell

unread,
Oct 21, 2016, 4:04:54 PM10/21/16
to Node-RED
Stuart,

That makes two of us. (My coding credentials have long since expired.) Thankfully, his group has taught me just enough to be dangerous. 

Mike

Julian Knight

unread,
Oct 24, 2016, 8:06:36 AM10/24/16
to Node-RED
Please let me know if there is anything I can do to make things easier. It is somewhat inevitable that the formatting instructions are a little hard to parse to begin with if you aren't into programming. 

It quickly gets hard for a developer to make sure their docs are understandable by all so I'd welcome any feedback. The best way is to raise an issue on Github but you can also drop a note into this group.

Scott C. Lemon

unread,
Oct 24, 2016, 12:07:53 PM10/24/16
to Node-RED
Not sure if this helps or not, but I often use this simple snippet to add timestamps ...

var jsonDate = (new Date()).toJSON();
msg.payload.eventTimestamp = jsonDate;

You probably can do some additional formatting ...

Julian Knight

unread,
Oct 24, 2016, 2:16:27 PM10/24/16
to Node-RED
Or 

(new Date()).toISOString()

Julian Knight

unread,
Oct 24, 2016, 2:18:18 PM10/24/16
to Node-RED
Not always a good idea to try and format date/time strings though as there are too many edge cases. Hence the Moment.js library and my contributed node.
Reply all
Reply to author
Forward
0 new messages