javasecript 生成 从2022年到当前季度的所以季度,排倒序

javasecript  生成 从2022年到当前季度的所以季度,排倒序

 

function getQuarter(year, quarter) {
    return year + "年" + quarter + "季度";
}

function generateQuarters() {
    var currentYear = new Date().getFullYear();
    var currentQuarter = Math.floor((new Date().getMonth() / 3) + 1);

    var curQuarterStr = getQuarter(currentYear, currentQuarter);
    var quarters = [];

    for (var year = currentYear; year >= 2022; year--) {
        var startQuarter = (year === currentYear) ? currentQuarter : 4;
        var endQuarter = (year === currentYear) ? currentQuarter : 4;

        for (var quarter = startQuarter; quarter >= 1; quarter--) {
            var quarterStr = getQuarter(year, quarter);
            if (curQuarterStr != quarterStr) {
                quarters.push(quarterStr);
            }
        }
    }

    return quarters;
}

var quarters = generateQuarters();
console.log(quarters);

 

posted @ 2023-06-06 15:59  三瑞  阅读(13)  评论(0编辑  收藏  举报