Moment JS start and end of given month

前端 未结 11 1471
无人及你
无人及你 2020-11-28 08:19

I need to calculate a JS date given year=2014 and month=9 (September 2014).

I tried this:

var moment = require(\'moment\');
var startDate = moment( y         


        
11条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 08:53

    you can use this directly for the end or start date of the month

    new moment().startOf('month').format("YYYY-DD-MM");
    new moment().endOf("month").format("YYYY-DD-MM");
    

    you can change the format by defining a new format

提交回复
热议问题