I implemented this logic where I am getting difference between 2 dates and times from Moment.js as seconds, and I need to convert these seconds into 1 Year 3 Months 10 Days 5 Hours 45 Minutes
format.
var numyears = Math.floor(seconds / 31536000);
var nummonths = Math.floor((seconds % 31536000) / 2628000);
var numdays = Math.floor(((seconds % 31536000) % 2628000) / 86400);
var numhours = Math.floor((((seconds % 31536000) % 2628000) % 86400)/3600);
var numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60);
I am getting the correct values up to days, but it's having problem from hours onwards.