How to extract time from "node-red-contrib-sunpos"?

#1

Hi all,
I installed "node-red-contrib-sunpos" to display the position of the sun in real time. This function works.
This node is used to display the sunset time "msg.payload.endTime" as can be seen on the debug (N°1): in seconds.
InkedendTime_LI
If I click on the Debug payload (N°2): endTime is displayed in Hexa
If I still click (N°3) I display in world time (?)
If I click again (N°4) I display in local time "UTC + 2" => It is this last value that I wish to recover from this Node.

Note: we see this value under the Node. (Status node)

Do you know how I can recover this value directly in UTC + 2?

Thank you

0 Likes

#2

Search "JavaScript epoch to date and time" (or similar)

Alternatively, install the "moment" node to do format conversions.

0 Likes

#3

Thanks for the answer, I'll watch this.
It's still annoying to have recourse to an additional node, whereas the "suncalc" node already has this function of epoch => date & time, integrated. I do not like to change the already existing flow, but I will try ... to pass the time lol

0 Likes

#4

Why not ask the author to include that in the returned data or even better fix the code and do a pull request on it?

0 Likes

#5

you're right, I'll do all this :wink:

0 Likes

#6

And here it is done thanks to @alisdairjsmyth :star_struck:

var d = new Date (msg.payload.endTime);
var n = d.toLocaleTimeString ();
msg.endLocaleTime = n;

// ********** displays the status of the Node **********
node.status ({text: n});

return msg;

image

0 Likes