比特币网站怎么做,网站你应该明白我的意思吗,深圳数据中心建设公司,网站建设中外链与内链的技巧需求
计算当前赛季的开始和结束日期#xff0c;2024年1月1日周一是第1周的开始#xff0c;每两周是一个赛季。
lua代码
没有处理时区问题
local const 24 * 60 * 60 --一整天的时间戳
local server_time 1716595200--todo:修改服务器时间
local date os.date(*t…需求
计算当前赛季的开始和结束日期2024年1月1日周一是第1周的开始每两周是一个赛季。
lua代码
没有处理时区问题
local const 24 * 60 * 60 --一整天的时间戳
local server_time 1716595200--todo:修改服务器时间
local date os.date(*t, server_time) -- 服务器当前时间对应的日期
local first_day_of_2024 os.time({ year 2024, month 1, day 1 })
-- os.date()返回的数据里周日才是一周的开始即 wday 1而我需要的是周一才
-- 是一周的开始所以做了处理
local week_day date.wday - 1
if week_day 0 thenweek_day 7
end
local total_time_stamps server_time - first_day_of_2024
local days math.ceil(total_time_stamps / const) -- 计算当前是第几天
-- 第几周或者 math.ceil((days (7 - week_day)) / 7)原理是凑完整的一周
local weeks math.ceil(days / 7)
local diff_time 0
if weeks % 2 0 thendiff_time 7 * const
end
local start_time_stamps os.time({ year date.year, month date.month, day date.day }) - week_day * const 1 * const - diff_time
local start_date os.date(*t, start_time_stamps) -- 得到开始日期
local end_time_stamps start_time_stamps 2 * 7 * const - const
local end_date os.date(*t, end_time_stamps) -- 得到结束日期当前时间是2024.5.25得到的赛季时间是5.20到6.2.