作为一个例子,我想在 LUA 中获取 (UTC) +0000 UTC 日期和时间。
我知道对此有一些答案,但没有一个不是我的答案。回答这个问题的一般方法是查找本地时间,然后加上或减去 UTC 数字,但我不知道我的操作系统时区,因为我的程序运行在不同的位置,并且我无法从我的开发环境中获取时区。
简而言之,如何使用 LUA 函数获取 UTC 0 日期和时间?
最佳答案
如果需要生成epg,则:
local timestamp = os.time()
local dt1 = os.date( "!*t", timestamp ) -- UTC
local dt2 = os.date( "*t" , timestamp ) -- local
local shift_h = dt2.hour - dt1.hour + (dt1.isdst and 1 or 0) -- +1 hour if daylight saving
local shift_m = 100 * (dt2.min - dt1.min) / 60
print( os.date("%Y%m%d%H%M%S ", timestamp) .. string.format('%+05d' , shift_h*100 + shift_m ))
关于date - 获取 Lua 中的特定 UTC 日期和时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43600810/