I have been fiddling with this for hours now (yes, really) ... I am new at this so I need to put in some research time before I run to the forums.
In the node-red debug pane I can output a timestamp as a numeric entry:
1587723989
When I click on that hyper-linked value I get the nice little ISO date/time:
2020-04-24T10:26:29.000Z
I am outputting this to MQTT so I want to insert a function node to do the exact same function that clicking in the debug window is doing.
var d = new Date();
// the question is what goes here to populate the d variable to perform the same conversion as the debug pane
var n = d.toISOString();
I tried the "moment" and "simpletime" nodes and never got them working properly, plus would prefer to know how to code this simple conversion in a function node.
Thanks for any guidance! I have just been coding in node-red a couple days.
The formatting of the output will probably not be an issue, it is the population of the date/time variable using the number. What I was looking for was something like:
var d new Date();
d.populateDateFromEpochNumber(myNumber); <- this is the magic function I search for
Steve,
I knew I had tried that before but the string I got from the following code is not the correct date
var d = new Date(msg.payload); // payload has 1587732484
var n = d.toISOString();
msg.payload = n;
return msg; // msg.payload now has "1970-01-19T09:02:12.484Z"
for the number: 1587732484 shown in the debugger pane...
clicking on the hyperlinked number shows: (the correct value)
2020-04-24T12:48:04.000Z