In Moment.js, how do you get the current financial Quarter?

后端 未结 9 1682
深忆病人
深忆病人 2020-12-14 16:07

Is there a simple/built in way of figuring out the current financial quarter?

ex:

  • Jan-Mar: 1st
  • Apr-Jul: 2nd
  • Jul-Sept: 3rd
9条回答
  •  囚心锁ツ
    2020-12-14 16:58

    There is nothing built in right now, but there is conversation to add formatting tokens for quarters. https://github.com/timrwood/moment/pull/540

    In the meantime, you could use something like the following.

    Math.floor(moment().month() / 3) + 1;
    

    Or, if you want it on the moment prototype, do this.

    moment.fn.quarter = function () {
        return Math.floor(this.month() / 3) + 1;
    }
    

提交回复
热议问题