JS实现获取日期天数差

ymd格式,精确到天数差


var s1='2018-5-1';

a1 = new Date(s1.replace(/-/g, "/"));   
a2 = new Date();//获取当前日期
var day = a2.getTime() - a1.getTime();

var time = parseInt(day / (1000 * 60 * 60 * 24));

alert(time);

猜你喜欢

转载自blog.csdn.net/Wicked_Child/article/details/80265000