JavaScript中的easter_date() [英] easter_date() in JavaScript

查看:95
本文介绍了JavaScript中的easter_date()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JavaScript制作日历生成器。对于给定的一年,我需要复活节当天午夜的Unix时间戳。谁能告诉我我需要怎么做(用JavaScript)?

I'm making a calendar generator in JavaScript. I need the Unix Timestamp for easter day midnight, for a given year. Can anyone tell me how I need to do that (in JavaScript)?

提前致谢。

PHP's功能可以在这里找到: http://www.php.net/easter_date

PHP's function can be found here: http://www.php.net/easter_date

推荐答案

根据这个: -

function Easter(Y) {
    var C = Math.floor(Y/100);
    var N = Y - 19*Math.floor(Y/19);
    var K = Math.floor((C - 17)/25);
    var I = C - Math.floor(C/4) - Math.floor((C - K)/3) + 19*N + 15;
    I = I - 30*Math.floor((I/30));
    I = I - Math.floor(I/28)*(1 - Math.floor(I/28)*Math.floor(29/(I + 1))*Math.floor((21 - N)/11));
    var J = Y + Math.floor(Y/4) + I + 2 - C + Math.floor(C/4);
    J = J - 7*Math.floor(J/7);
    var L = I - J;
    var M = 3 + Math.floor((L + 40)/44);
    var D = L + 28 - 31*Math.floor(M/4);

    return padout(M) + '.' + padout(D);
}

function padout(number) { return (number < 10) ? '0' + number : number; }

用法示例: -

document.write(Easter(1997));

这篇关于JavaScript中的easter_date()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆