mirror of
https://github.com/wxd-gaming/test-all.git
synced 2026-05-08 06:28:01 +08:00
【新增】lua调试代码
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
---
|
||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||||
--- Created by 無心道(15388152619).
|
||||
--- DateTime: 2024/11/11 11:27
|
||||
---
|
||||
|
||||
TimeUtil = {}
|
||||
|
||||
--- 将秒时间戳转换为日期表
|
||||
function TimeUtil.timeToDate(timestamp)
|
||||
return os.date("*t", timestamp)
|
||||
end
|
||||
|
||||
--- 根据毫秒时间戳获取年月日零点时间戳
|
||||
function TimeUtil.creteTimeZero4Mill(mill)
|
||||
local date = TimeUtil.timeToDate(math.floor(mill / 1000))
|
||||
return TimeUtil.creteTimeZero(date.year, date.month, date.day)
|
||||
end
|
||||
|
||||
--- 根据秒时间戳获取年月日零点时间戳
|
||||
function TimeUtil.creteTimeZero4Sec(sec)
|
||||
local date = TimeUtil.timeToDate(sec)
|
||||
return TimeUtil.creteTimeZero(date.year, date.month, date.day)
|
||||
end
|
||||
|
||||
--- 获取年月日零点时间戳
|
||||
function TimeUtil.creteTimeZero(year, month, day)
|
||||
print("creteTimeZero", year, month, day)
|
||||
return os.time({ year = year, month = month, day = day, hour = 0, min = 0, sec = 0 })
|
||||
end
|
||||
|
||||
--- 计算两个日期之间的天数差
|
||||
function TimeUtil.diff(sec1, sec2)
|
||||
local timestamp1 = TimeUtil.creteTimeZero4Sec(sec1)
|
||||
local timestamp2 = TimeUtil.creteTimeZero4Sec(sec2)
|
||||
-- 计算两个时间戳之间的差值
|
||||
local difference = math.abs(timestamp2 - timestamp1)
|
||||
-- 将差值转换成天数
|
||||
local days = difference / (24 * 60 * 60)
|
||||
return math.floor(days)
|
||||
end
|
||||
|
||||
local v1 = TimeUtil.creteTimeZero(2024, 11, 11)
|
||||
local v2 = TimeUtil.creteTimeZero(2024, 11, 15)
|
||||
print(v1, v2, TimeUtil.diff(v1, v2))
|
||||
print(TimeUtil.creteTimeZero4Sec(200000))
|
||||
Reference in New Issue
Block a user