Change HH:MM into seconds

Hello.
Anyone help?

How can I convert a time input of HH:MM (ie:07:30) into seconds (since midnight)?

Cheers!

I'd recommend looking into node-red-contrib-moment (node) - Node-RED

1 Like

You could use a function node:

p = msg.payload.split(":")
seconds = (p[0]*60)*60 + (p[1]*60)
return {payload:{input:msg.payload,seconds:seconds}}

Or a change node with a jsonata expression

$number($split(payload,":")[0])*60*60+$number($split(payload,":")[1])*60

2 Likes

Is that a string or what? If you don't know then feed it into a debug node and show us.

with change node and JSONata

$toMillis("1970-01-01T"&payload&":00.000")/1000

with function node

msg.payload = new Date("1970-01-01T"+msg.payload+":00.000").valueOf()/1000;
return msg;
2 Likes

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