How to convert 340047 seconds into days and hours duration with Moment.js?
You don't need moment.js.
You can calculate the days by dividing the seconds by 86400.
You can calculate the hours by dividing the seconds by 3600, then subtracting the hours in the number of days.
const seconds = 340047;
const days = Math.floor(seconds / 86400);
const hours = Math.floor(seconds / 3600) - (days * 24);
console.log('Days:', days, 'Hours:', hours)
You can use moment#duration to do it.
const moment = require("moment");
let s = 340047;
var diff = new moment.duration(s * 1000);
console.log('Days: ',Math.floor(diff.asDays()), 'Hours: ',Math.floor(diff.asHours()) % 24);
outputs
Days: 3 Hours: 22