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

前端 未结 7 787
攒了一身酷
攒了一身酷 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:11

    What I have guessed is if current month is February then your output should be 1,31 because January's first day and last day is 1 and 31. So if that is the case then

    var toDay = new Date();
    var myDate = new Date(2016,toDay.getMonth()-1);
    Fri Jan 01 2016 00:00:00 GMT+0530 (India Standard Time)
    

    This will be assigned with the first day of the previous month.

    Also, for the second case

    var myDate = new Date(2016, toDay.getMonth());
    myDate = new Date(myDate -1);
    Sat Jan 31 2015 23:59:59 GMT+0530 (India Standard Time)
    

    You can just use myDate to find whatever you want.

提交回复
热议问题