从 os.date() 中减去小时数

Cra*_*aig 3 lua

我目前有这个代码

local day = os.date('%A')
local timesubtract = 8 --GMT -8 hours
local hour = os.date('%H')
local newtime = (day-timesubtract)
Run Code Online (Sandbox Code Playgroud)

显然它不起作用。在过去的 3-4 个小时里,我一直在论坛上筛选帖子,但没有运气

基本上,我需要调用特定时区的星期几。例如,今天是星期六,但世界上的其他地方可能仍然是星期五,如果偏移量设置在“timesubtract”中,它将调用该时区的正确星期几。

You*_*uka 5

你可以在几秒钟的时间(因为在过去的特定点)与os.time,添加偏移(以秒为单位)和格式化此为一个字符串(或表,不管你喜欢)与os.date

print(os.date("%c"))    -- Print current time (08/15/15 10:45:55)

local seconds_since_xxx = os.time() -- Get current time in seconds
seconds_since_xxx = seconds_since_xxx - (60 * 60 * 11)  -- Subtract 11 hours from time

print(os.date("%c", seconds_since_xxx)) -- Print calculated time (08/14/15 23:45:55)
Run Code Online (Sandbox Code Playgroud)