According to this question, I wrote "my code" (without Math.abs, I don't need it) :
var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
var firstDate = new Date("2011", "09", "28"); // 28 september 2011
var secondDate = new Date("2011", "09", "30"); // 30 september 2011
var notti = ((secondDate.getTime() - firstDate.getTime()) / (oneDay));
if (notti < 1)
notti = 1;
else
notti = Math.round(notti);
alert(notti);
and it print 2 (correct).
Now, If I do this :
var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
var firstDate = new Date("2011", "09", "28"); // 28 september 2011
var secondDate = new Date("2011", "10", "01"); // 01 october 2011
var notti = ((secondDate.getTime() - firstDate.getTime()) / (oneDay));
if (notti < 1)
notti = 1;
else
notti = Math.round(notti);
alert(notti);
it print 4. Why 4? It should be 3...
Do you know about this problem?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…