JS-就当前时间往前推49天、30天、7天、3天的日期

function getData(day){
    var today=new Date()
    var targetday=today.getTime() +1000*60*60*24* day
    today.setTime(targetday)
    var tYear=today.getFullYear()
    var tMonth=today.getMonth()
    var tDate=today.getDate()
    tMonth=this.doHandMonth(tMonth+1)
    tDate=this.doHandMonth(tDate)
    return tYear +"-" + tMonth+"-"+tDate
}
 
 
function doHandMonth(month){
    var m=month
    if(month.toString().length==1){
    m="0"+month
    }
    return m
}
console.log("前推49天:",getData(-49))
console.log("前推30天:",getData(-30))
console.log("前推7天:",getData(-7))
console.log("前推3天:",getData(-3))

 

 

 

posted @ 2022-12-28 16:55  MiniDuck  阅读(956)  评论(0编辑  收藏  举报