How to calculate the year / month / day hh:mm:ss of the difference according to the difference (ms)

according to the long integer obtained, the UI needs to indicate how long a Server has been activated, such as 14:22:38 on the 4th day of a month, for example, 1 year

.

the following is my code:

function deltaTimeFormatter(ms){
            if(!ms)
                return "N/A";

            var totalS, totalMin, totalH, d, h, min, s;
            totalS = Math.floor(ms / 1000);
            totalMin = Math.floor(totalS / 60);
            s = String(totalS % 60);
            totalH = Math.floor(totalMin / 60);
            min = String(totalMin % 60);
            d = Math.floor(totalH / 24);
            h = String(totalH % 24);

            let str = `${h.padStart(2, "0")}:${min.padStart(2, "0")}:${s.padStart(2, "0")}`;
            str = (d ? d + "days, " : "") + str;
            return str ;
        }

at present, I can only calculate xx days, hh:mm:ss, years, months, days, etc. It depends on the size of months, leap years, etc., is there any way to calculate?

Oct.20,2021

recommends moment.js. I remember that there is a diff function that calculates the difference between two time points

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3815a-2c0e0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3815a-2c0e0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?