公告
财富商城
积分规则
提问
发文
2020-02-23 06:17发布
forever°为你锁心
Is there a simple/built in way of figuring out the current financial quarter?
ex:
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; }
The formula that seems to work for me is:
Math.ceil((moment().month() + 1) / 3);
moment().month() gives back the 0-11 month format so we have to add one
THE ACTUAL MONTH = (moment().month() + 1)
then we have to divide by 3 since there are 3 months in a quarter.
HOW MANY QUARTERS PASSED = (THE ACTUAL MONTH) / 3
and then we have to get the ceiling of that (round to the nearest quarter end)
CEILING(HOW MANY QUARTERS PASSED)
EDIT:
The Official formula (not commited yet) is:
~~((this.month()) / 3) + 1;
which means Math.floor((this.month()) / 3) + 1;
Math.floor((this.month()) / 3) + 1;
最多设置5个标签!
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.
Or, if you want it on the moment prototype, do this.
The formula that seems to work for me is:
moment().month() gives back the 0-11 month format so we have to add one
then we have to divide by 3 since there are 3 months in a quarter.
and then we have to get the ceiling of that (round to the nearest quarter end)
EDIT:
The Official formula (not commited yet) is:
which means
Math.floor((this.month()) / 3) + 1;