var years = Math.floor(seconds / (3600*24*365))
seconds -= years*3600*24*365
var days = Math.floor(seconds / (3600*24))
seconds -= days*3600*24
var hrs = Math.floor(seconds / 3600)
seconds -= hrs*3600
var minutes = Math.floor(seconds / 60)
seconds -= minutes*60
console.log(formatDuration(3662)); // 1 hour, 1 minute and 2 second
console.log(formatDuration(62)); // 1 minute and 2 second
console.log(formatDuration(94608000)); // 3 years
How to log the duration in the specified format? Thank you for your help.
If there is only one entity, no comma, no "and".
If there are two entities, use "and".
If there are three entities, use commas and "and".