【问题标题】:How to calculate leap year in jalali calendar?如何计算 jalali 日历中的闰年?
【发布时间】:2020-03-25 10:43:08
【问题描述】:

如您所知,贾拉利历每四年有一次飞跃(当然也有一些例外)

而不是一年有 365 天,而是有 366 天 :)

另一个问题是,有些月份是 29 天,有些月份是 30 天,有些月份是 31 天:|

我使用矩库来生成这些日期(当然使用 fa 方法)

这个叫تقویم的网站做得很好。

var moment = require('moment-jalaali')
moment().format('jYYYY/jM/jD')

现在我的问题是如何确定哪些月份是 29 和 30 和 31 闰年是哪一年?

【问题讨论】:

    标签: javascript jalali-calendar


    【解决方案1】:

    在我之前的项目中我遇到了同样的问题,你必须使用这种方法来做到这一点

    这个函数不在javascript中但是这个算法对你的闰年非常有效

    internal static bool IsLeapYear(int y)
    {
        int[] matches = { 1, 5, 9, 13, 17, 22, 26, 30 };
        int modulus = y - ((y / 33) * 33);
        bool K = false;
        for (int n = 0; n != 8; n++) if (matches[n] == modulus) K = true;
        return K;
    }
    

    【讨论】:

    • 是的,我在以前的项目中使用过它
    【解决方案2】:

    这是 Sina Rahmani 的回答的 JavaScript 版本(y / 30 应该向下舍入才能在 JavaScript 中正常工作):

    function isLeapYearJalali(year) {
        const matches = [1, 5, 9, 13, 17, 22, 26, 30];
        const modulus = year - (Math.floor(year / 33) * 33);
        let isLeapYear = false;
    
        for (let i = 0; i != 8; i++) {
            if (matches[i] == modulus) {
                isLeapYear = true;
            }
        }
    
        return isLeapYear;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-01
      • 2018-11-18
      相关资源
      最近更新 更多