date - 获取 Lua 中的特定 UTC 日期和时间

标签 date datetime lua timezone

作为一个例子,我想在 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/

相关文章:

java - Date.plus 在 2.5.4 Groovy Runtime 中不起作用,有什么替代方法?

javascript - 如何检查日期是否在 30 天内?

json - 正文中带有 json 的原始 POST 请求

lua - 有关 Lua C API 函数参数的详细信息

sql - 甲骨文日期/按问题排序

php - 获取本周星期一和星期五的日期 (PHP)

C# 无法将字符串转换为日期时间

python - 从周数获取日期

android - 以毫秒为单位的时差问题

lua - 调试元表脚本中的意外空值