Recently, I stumbled upon this fascinating codepen https://codepen.io/donovanh/pen/JWdyEm, and was excited to integrate its features into an older countdown timer that I had created. However, when I set the countdown date to today, it still displays incorrect information stating there are 30 days left.
Here is the snippet of code responsible for calculating the difference between dates.
function daysBetween( date1, date2 ) {
//Get 1 day in milliseconds
var one_day=1000*60*60*24;
// Convert both dates to milliseconds
var date1_ms = date1.getTime();
var date2_ms = date2.getTime();
// Calculate the difference in milliseconds
var difference_ms = date2_ms - date1_ms;
// Convert back to days and return
return Math.round(difference_ms/one_day);
}
console.log("Days to end of April = " +
daysBetween(new Date(), new Date("2018-04-30")));
I'm perplexed as to why these extra days seem to be added. Any assistance or insights on this issue would be greatly appreciated. Thank you.