Get current quarter in year with javascript

后端 未结 9 1071
有刺的猬
有刺的猬 2020-12-13 02:10

How can I get the current quarter we are in with javascript? I am trying to detect what quarter we are currently in, e.g. 2.

EDIT And how can I coun

9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 02:42

    if the first solution doesn't work than you can just adjust it to the range you would like

    var today = new Date();
    var month = now.getMonth();
    var quarter;
    if (month < 4)
      quarter = 1;
    else if (month < 7)
      quarter = 2;
    else if (month < 10)
      quarter = 3;
    else if (month < 13)
      quarter = 4;
    

提交回复
热议问题