问题
As an illustration, I want to grab the (UTC) +0000 UTC date and time in LUA.
I know there are some answers about this but none of them isn't my answer. The general approach to answering this issue is Find Local Time, then plus or minus the UTC number but I don't know my OS Time Zone because my program cab be run in different locations and I cannot get the timezone from my development environment.
Shortly, How can I get the UTC 0 date and time using LUA functions?
回答1:
If you need to generate epg, then:
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 ))
来源:https://stackoverflow.com/questions/43600810/get-specific-utc-date-and-time-in-lua