📜 ⬆️ ⬇️

Glitch IE with calculating date differences, Javascript

Hello!
Made a simple countdown counter on js (code below).

It was accidentally discovered that in different browsers the counting numbers differ.
By simple checks it turned out:
1) count ('31 ',' Oct ',' 2010 ') returns 192 days everywhere (data from April 21, 2010).
2) count ('01 ',' Nov ',' 2010 ') returns 193 days everywhere, except IE, in which the result is 194.

And in the future, the result is aligned. Those.:
1) count ('27 ',' Mar ',' 2011 ') - everywhere 339, in IE - 340.
2) count ('28 ',' Mar ',' 2011 ') - 340 everywhere (including IE).
')
PS IE 8.0, compared with Opera, Firefox and Chrome.

Counter Code:
function count(dt,mt,yr){
theDate = mt + ' ' + dt + ' ' + yr;
now = new Date();
setdate = new Date(theDate);
timer = (setdate - now) / 1000 / 60 / 60 / 24;
timer = Math.round(timer);
return timer
}

Source: https://habr.com/ru/post/91594/


All Articles