Hi all… what would the code be that goes into a function node to take a timestamp and output the date and time in the normal date and time format?
You can write down a function, can take a look for it I have it somewhere in my code however the more easy is use a node called moment, is what I’m using most frequently.
I’m using this on several ways and make a global set of the formatted date, then on any function u can directly recall the global variable and get the date formatted directly as u wish.
Hey…brilliant guys… thanks. Both those suggestions work. I have gone with the moment node as I managed to get it to display local time - but I did like the json cheat…
Yep Moment.JS is brilliant. The other day i decided to write function to get the date and time into a reasonable format so i could pipe it out inline to a log file with some status info.
After spending 4 hours cruising around (learning a LOT), decided it was a waste of time and far smarter to do it in the moment node - took all of 10 minutes to get it up and running
I'm amazed that some brilliant chap wrote the moment node to help in situations like this
To be fair though, Moment.js, while excellent, is BIG. You should avoid it if resources are an issue. But it is comprehensive and does cover pretty much every edge-case for date/time handling.
Yep he is brilliant - should give up his day job !!
I run my Node-red on a Ubuntu VM so resources are not really an issue for me
Haha, sadly his day job pays rather too well to give up right now A few years yet until I can do a "Pete Scargill" and retire
Gotta keep the dream alive !!
If you want a lightweight solution, try
With this cheat...how can I get the payload/message to also be included in the timestamp?
Example I have a GPIO pin that goes to a change node. It changes a 0 or 1 to a message and then off to an email node. I would like to have it include a timestamp and the message.
payload &" "& $now(), for example.
Thank you so much! I am new to this and trying to teach myself. I understand some complex things..but get tripped on the simple stuff from time to time.