Convert Millisecond to H

Hi
I'm stuck, again...

I want to change/convert the date format in my whole array, feels like it would be very easy but after hours of googling I haven't succeeded, hope someone here can give me a hint :slight_smile:

The "series" are in "Unix Millisecond Timestamp" and a want simpel change/convert that to Hour (2 numbers in "24h". ex.21)

[{"series":1670115300004,"value":5.07},{"series":1670115300004,"value":2.88},{"series":1670115300004,"value":0},{"series":1670115300004,"value":0},
and a lot more.....]

You could use a change node and JSONata and $moment().format() to format "HH" 24hr
e.g.

[{"id":"eb138f9de06c8ae5","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"series\":1670115300004,\"value\":5.07},{\"series\":1670115300004,\"value\":2.88},{\"series\":1670115300004,\"value\":0},{\"series\":1670115300004,\"value\":0}]","payloadType":"json","x":270,"y":4080,"wires":[["2be6fc547b8bc787"]]},{"id":"2be6fc547b8bc787","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload ~> |$|{\"series\":$moment($.series).format(\"HH\")}|","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":4120,"wires":[["13e2a3b6387671ee"]]},{"id":"13e2a3b6387671ee","type":"debug","z":"452103ea51141731","name":"debug 112","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":610,"y":4080,"wires":[]}]

Expression

$$.payload ~> |$|{"series":$moment($.series).format("HH")}|

You can also use Javascript in a function node. Or low code split node > moment node > join node, to convert the array object

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.