输入某年某月,如何返回当前月的的最后一天

输入某年某月,如何返回当前月的的最后一天?
废话不多说直接上代码
代码实现:
        function getLastDayOfMonth(year, month) {
          var date = new Date(year, month);             //   console.log(date.getFullYear(), date.getMonth(), date.getDate());        2023 2 1
          let res = new Date(date.getTime() - 1000 * 60 * 60 * 24);         //      console.log(res.getFullYear(), res.getMonth(), res.getDate());      2023 1 28
          let newDate = res.getFullYear() + "-" + (res.getMonth() + 1) + "-" +  res.getDate() + " " + "23" + ":" +  "59" + ":" + "59";   
          let dates = new Date(newDate);
          const time = dates.getTime();
          return time;
      }
  调用:
      let res = getLastDayOfMonth(2023, 2);
//    res = 1677599999000 
![](https://img2022.cnblogs.com/blog/2485085/202204/2485085-20220427170519669-650079679.png)



posted @ 2022-04-27 17:48  爱划水的小刚哥  阅读(66)  评论(0编辑  收藏  举报