# Convert Millisecond to H

**URL:** <https://discourse.nodered.org/t/convert-millisecond-to-h/71733>\
**Category:** General\
**Tags:** function-node\
**Created:** [5 December 2022 22:07 UTC](https://discourse.nodered.org/t/convert-millisecond-to-h/71733 "2022-12-05T22:07:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![axdig](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@axdig](https://discourse.nodered.org/u/axdig)\
**Post date:** [5 December 2022 22:07 UTC](https://discourse.nodered.org/t/convert-millisecond-to-h/71733/1 "2022-12-05T22:07:58Z")

</div>

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 🙂

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.....]

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [5 December 2022 22:33 UTC](https://discourse.nodered.org/t/convert-millisecond-to-h/71733/2 "2022-12-05T22:33:14Z")

</div>

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

```auto
[{"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

```auto
$$.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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 February 2023 22:33 UTC](https://discourse.nodered.org/t/convert-millisecond-to-h/71733/3 "2023-02-03T22:33:46Z")

</div>

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