如果需要财政、日历或学术季度,可以使用 @robgallen 的 moment-fquarter 插件。
最简单的是,只需在任何 moment 对象上调用 fquarter 方法。 它返回格式化的字符串,其中四月是第一季度。
moment("2013-01-01").fquarter();
// Q4 2012/13
可以将任何月份作为起始季度,例如七月:
moment("2013-01-01").fquarter(7);
// Q3 2012/13
如果需要日历季度,则从一月开始:
moment("2013-01-01").fquarter(1);
// Q1 2013
If you ever have need for Fiscal, Calendar or Academic quarters, you can use the moment-fquarter plugin by @robgallen.
At its simplest, just call the fquarter method on any moment object. It returns a formatted string with April being the first quarter.
moment("2013-01-01").fquarter();
// Q4 2012/13
You can pass in any month as the starting quarter, e.g. July
moment("2013-01-01").fquarter(7);
// Q3 2012/13
If you want calendar quarters, start in January
moment("2013-01-01").fquarter(1);
// Q1 2013