1. const totalSeconds = (newYearsDate - currentDate)/1000;
2. const days = Math.floor(totalSeconds/3600/24);
3. const hours = Math.floor(totalSeconds/3600)%24;
4. const mins = Math.floor(totalSeconds/60)%60;
5. const seconds = Math.floor(totalSconds)%60;
1. The difference between the dates is in milliseconds, so divide by 1000 to get seconds.
2. 3600 seconds (60 * 60) in an hour, so divide by 3600, and then by 24 to get the days from the seconds
3. Divide by 3600 to get the number of hours, and use the modulo function to get the remainder after dividing by 24, gives the number of hours on the final day.
4. Similar to 3 to get the number of minute.
5. And the residual number of seconds.
If you feed a few dates in to the function you can see the results.