javascript - Moment.js how do you get the current Quarter and previous three quarters along with year? -
is there way current quarter , previous 3 quarters along year, example should return 4 quarters this
q3-2016 q2-2016 q1-2016 q4-2015
here's solution using moment.js:
const moment = require('moment'); let fmt = '[q]q-y'; let quarters = [ moment().format(fmt), moment().subtract(1, 'q').format(fmt), moment().subtract(2, 'q').format(fmt), moment().subtract(3, 'q').format(fmt) ]; // quarters = [ 'q3-2016', 'q2-2016', 'q1-2016', 'q4-2015' ]
or more concise version:
let quarters = [ 0, 1, 2, 3 ].map(i => moment().subtract(i, 'q').format('[q]q-y') )
Comments
Post a Comment