js获取前七天的日期

 var now = new Date();//获取当前时间

 var nowMs = now.getTime();//获取当前时间的毫秒数

 var beforeMs =  nowMs -  1000 * 60 * 60 * 24 * parseInt(n);//前几天,n就取几,整数

 var beforeDate = new Date().setTime(beforeMs );

 beforeDate 就是要去的日期

 用循环来做的话,就能得出前七天,后7天等

    

猜你喜欢

转载自blog.csdn.net/liuguochao1024/article/details/79576365