How to get last day of the month

后端 未结 9 993
闹比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:35
    var month = 1; // 1 for January
    var d = new Date(2015, month, 0);
    console.log(d); // last day in January
    
    0 讨论(0)
  • 2021-02-01 21:35

    Last day of the month

    now = new Date
    lastDayOfTheMonth = new Date(1900+now.getYear(), now.getMonth()+1, 0)
    
    0 讨论(0)
  • 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)

    0 讨论(0)
提交回复
热议问题