How to get last day of the month

后端 未结 9 990
闹比i
闹比i 2021-02-01 20:37

How can I obtain the last day of the month with the timestamp being 11:59:59 PM?

9条回答
  •  既然无缘
    2021-02-01 21:28

    function LastDayOfMonth(Year, Month) {
      return new Date((new Date(Year, Month, 1)) - 1);
    }
    
    console.log(LastDayOfMonth(2009, 11))

    Example:

    > LastDayOfMonth(2009, 11)
    Mon Nov 30 2009 23:59:59 GMT+0100 (CET)
    

提交回复
热议问题