我怎样才能知道礼拜二的日期(12/02/2013,04/03/2014,17/02/2015等)在卢阿供应的一年里?如果可能的话,能不能解释清楚,以适应复活节、母亲节和其他每年都在变化的节日?有一些在线脚本可以得到复活节,但它们没有得到很清楚的解释,我不知道我如何能够改变他们在Shrove星期二和其他假期。
发布于 2014-03-02 02:14:01
据维基百科报道,Shrove星期二正好是复活节前47天。所以关键是如何计算复活节,一个可移动的节日。您可以修改计算复活节的代码以获得Shrove星期二。
function shrove_tuesday(year)
local leap_year
if year % 4 == 0 then
if year % 100 == 0 then
if year % 400 == 0 then
leap_year = true
else
leap_year = false
end
else
leap_year = true
end
else
leap_year = false
end
local a = year % 19
local b = math.floor(year / 100)
local c = year % 100
local d = math.floor(b / 4)
local e = b % 4
local f = math.floor((b + 8) / 25)
local g = math.floor((b - f + 1) / 3)
local h = (19 * a + b - d - g + 15) % 30
local i = math.floor(c / 4)
local k = c % 4
local L = (32 + 2 * e + 2 * i - h - k) %7
local m = math.floor((a + 11 * h + 22 * L) / 451)
local month = math.floor((h + L - 7 * m + 114 - 47) / 31)
local day = (h + L - 7 * m + 114 - 47) % 31 + 1
if month == 2 then --adjust dates in February
day = leap_year and day - 2 or day - 3
end
return day, month
end计算似乎很复杂,这是因为计算复活节是复杂的,这个函数遵循计算图算法。
测试:
print(shrove_tuesday(2012))
print(shrove_tuesday(2013))
print(shrove_tuesday(2014))
print(shrove_tuesday(2015))输出:
21 2
12 2
4 3
17 2您可以很容易地使用day和month获得格式化字符串,使用string.format("%02d/%02d/%04d", day, month, year)或您需要的任何东西。
https://stackoverflow.com/questions/22122881
复制相似问题