当前位置:网站首页>Use js to obtain the last quarter based on the current quarter

Use js to obtain the last quarter based on the current quarter

2022-06-26 00:11:00 Daily log of the great demon king

var myDate = new Date();
var today= myDate.toLocaleDateString();// Get current date
var strYear = myDate.getFullYear();
var strMonth = myDate.getMonth() + 1;
var strQuarter = Math.floor((strMonth % 3 == 0 ? (strMonth / 3) : (strMonth / 3 + 1)));
strYear=((strQuarter==1)?(strYear-1):(strYear));

strQuarter=((strQuarter==1)?(4):(strQuarter-1));


Be careful : When the date is 01-01---03-31 Yes, in the first quarter , We need to put the year -1 That is, the fourth quarter of the previous year

incidentally : I wrote a get current date .

( You can refer to the judgment based on the current date to obtain the last quarter )


Here I write such a method , Another way is for the great God to discuss and share

原网站

版权声明
本文为[Daily log of the great demon king]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206252125482903.html