Timestamp ms to HH:MM:SS

Hi.

Have read in this forum to find a solution to convert timestamp. I found on jsonata homepage to get Day,Month and year nicely formatted but I have no luck with the time.
I just want HH:MM:SS from a ms timestamp.

If i use JSONata expression $now() I get this result 2020-01-14T22:17:17.823Z but I just want 22:17:17.

my solution is to use something like this $substring("????", 11, 18)

but I don't understand how I should combine $substring with $now()

maybe this doesn't work at all

Any idea?

$substring($now(), 11, 18)

Or look at node-red-contrib-moment which will allow you to format it how you like.

Thanks. You are amazing in this forum

1 Like

If you want to get time from a function here's another way, plus you can see how to get to the time components

let currentTime = new Date();
let hours = currentTime.getHours();
let minutes = currentTime.getMinutes();
let seconds = currentTime.getSeconds();
if (minutes < 10) {
minutes = "0" + minutes;
}
if (seconds < 10) {
seconds = "0" + seconds;
}
let z = hours + ':' + minutes + ':' + seconds;