Conver Decimal Number to HH:mm

Hello Guys,

So, i'm doing a dashboard to check all the stats on my electric car.
It's all going, now i have a function to get the Charge Remaining Time, and i receive a decimal value, like the one the print screen i've shared, "5.5" so after this, i want to get a result like "5h:30min"

How can i achieve this?

Best regards

One trick You can use is the epoch since 01/01/1970
converting the 5.5 to milliseconds and then using $fromMillis() JSONata expression to fromat the hours and minutes.
e.g

[{"id":"39f9ee50.cd87aa","type":"change","z":"c791cbc0.84f648","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$fromMillis($$.payload * 3600000, \"[H]h:[m]m\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":860,"wires":[["c4f45a89.bcb1d8"]]},{"id":"c4f45a89.bcb1d8","type":"debug","z":"c791cbc0.84f648","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":680,"y":860,"wires":[]},{"id":"d17a881.81b99f8","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"5.5","payloadType":"num","x":110,"y":860,"wires":[["39f9ee50.cd87aa"]]}]

JSONata expression

$fromMillis($$.payload * 3600000, "[H]h:[m]m")
1 Like

OMG Thank you for the response, exacly the result i wanted!!!

Screenshot from 2022-01-14 21-00-48

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