I am trying to convert seconds to hh:mm:ss
format with javascript. I found a lot of topics about this like this one, but I still have trouble implementing this.
This is my code:
function buildList(item, index) {
....
var listItemTime = $('.time', listItem);
listItemTime.html(secondsToHms(item.time));
$('#dataList').append(listItem);
}
function secondsToHms(d) {
var time = (new Date).clearTime()
.addSeconds(d)
.toString('H:mm:ss');
console.log(time);
return time;
}
I got an error: TypeError: (new Date(...)).clearTime is not a function
I also tried to use moment:
function secondsToHms(d) {
return moment().startOf('day')
.seconds(d)
.format('H:mm:ss');
}
And I got the error:
moment is not defined
I installed moment with npm install moment --save
and then tried to require it, but the component was not working anymore.