Your dateone
and datetwo
variables are String
s not Date
s.(您的dateone
和datetwo
变量是String
而不是Date
。)
Try this:(尝试这个:)
var dateone = new Date("2016-08-21T07:00:00.000Z");
var datetwo = new Date("2016-08-28T07:00:00.000Z");
Also, substracting 2 Date
s objects will give you the difference between them in milliseconds, if you want to determine the number of days, you can do something like this:(同样,减去2 Date
对象将为您提供它们之间的差(以毫秒为单位),如果要确定天数,则可以执行以下操作:)
var dayDif = (datetwo - dateone) / 1000 / 60 / 60 / 24;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…