- function getData(days){
-
var date1 = new Date(), -
time1=date1.getFullYear()+"-"+(date1.getMonth()+1)+"-"+date1.getDate();//time1表示当前时间 -
var date2 = new Date(date1); -
date2.setDate(date1.getDate()+days); -
var time2 = date2.getFullYear()+"-"+(date2.getMonth()+1)+"-"+date2.getDate(); -
return time2 -
} -
console.log('7七天后:',getData(7)) -
console.log('7七天前:',getData(-7))
购物网站中经常会用到限时购买,抢购等功能,在这些功能中又会涉及到获取当前时间之后固定天数时间如一周前后得时间点,那么js代码要如何实现获取一周后得具体时间呢?
代码如下:

