How to get last day of the month

后端 未结 9 991
闹比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:39

    var d = new Date();
    console.log(d);
    d.setMonth(d.getMonth() + 1); // set month as next month
    console.log(d);
    d.setDate(0); // get the last day of previous month
    console.log(d);

    Here is output from the code above:
    Thu Oct 03 2013 11:34:59 GMT+0100 (GMT Daylight Time)
    Sun Nov 03 2013 11:34:59 GMT+0000 (GMT Standard Time)
    Thu Oct 31 2013 11:34:59 GMT+0000 (GMT Standard Time)

提交回复
热议问题