Get the first and last date of the previous month in JQuery

前端 未结 7 791
攒了一身酷
攒了一身酷 2021-02-09 07:41

I have this script,

 var today = new Date();
 var dd = today.getDate();
 var ffffd = today.getDate()-1;
 var ffffdd = today.getDate()-2;

 var mm = today.getMonth()+         


        
7条回答
  •  被撕碎了的回忆
    2021-02-09 08:10

    You can do it like this

    //one day previous  Date
    var date = new Date();
    date.setDate(date.getDate() - 1);
    console.log(date.getDay());
    
    //for previous month last date 
    var date = new Date();
    date.setDate(0);
    console.log(date);
    
    //for perivous Month First date
    var date = new Date();
    date.setDate(0);
    date.setDate(1);
    console.log(date);

提交回复
热议问题