有老哥这个代码每句话含义嘛?
lua吧
全部回复
仅看楼主
level 5
function comparetime(strtime1, strtime2)
--比较现在的时间是不是在strtime1和strtime2之间
--比如 comparetime("20:00", "23:00")
--如果是就返回真
local time1 = os.date("*t")
local time2 = os.date("*t")
网页链接 = strtime1:sub(1,2)
网页链接 = strtime1:sub(4,5)
网页链接 = strtime2:sub(1,2)
网页链接 = strtime2:sub(4,5)
return os.time() >= os.time(time1) and os.time() <= os.time(time2)
end
2023年06月24日 12点06分 1
level 4
你想要的 Lua 函数应该如下所示:
```lua
function comparetime(strtime1, strtime2)
-- 提取输入字符串中的小时和分钟
local hour1, min1 = strtime1:sub(1,2), strtime1:sub(4,5)
local hour2, min2 = strtime2:sub(1,2), strtime2:sub(4,5)
-- 获取当前日期和时间
local now = os.date("*t")
local time1 = os.date("*t")
local time2 = os.date("*t")
-- 修改 time1 和 time2 来反映 strtime1 和 strtime2 的时间
网页链接 = hour1
网页链接 = min1
网页链接 = hour2
网页链接 = min2
-- 检查当前时间是否在 time1 和 time2 之间
local now_sec = os.time(now)
return now_sec >= os.time(time1) and now_sec <= os.time(time2)
end
```
此函数首先从输入的字符串中提取小时和分钟,然后获取当前的日期和时间。接下来,它修改 `time1` 和 `time2` 的小时和分钟以反映 `strtime1` 和 `strtime2` 中的时间。最后,它检查当前时间是否在 `time1` 和 `time2` 之间,并返回结果。
2023年07月04日 04点07分 2
level 5
谢谢大佬
2023年07月04日 05点07分 3
1