from Date I just want to subtract 1 day in javascript/angularjs

前端 未结 3 1377
暖寄归人
暖寄归人 2021-02-04 09:05

with the help of new Date() how i can achieve this. my code :

var temp =new Date(\"October 13, 2014 22:34:17\");
console.log(new Date(temp-1));

3条回答
  •  时光取名叫无心
    2021-02-04 09:49

    You need to specify what amount of time you are subtracting. At the moment its 1, but 1 what? Therefore, try getting the days using getDate() and then subtract from that and then set the date with setDate().

    E.g.

    var temp = new Date("October 13, 2014 22:34:17");
    temp.setDate(temp.getDate()-1);
    

提交回复
热议问题