Back and forth UTC dates in lua -


i'm having problems converting lua date timestamp , obtaining original date it. work non utc dates, not utc.

currently example code is:

local dt1 = os.date( "*t" ); print( dt1.hour );  local dt2 = os.date( "*t", os.time( dt1 ) ); print( dt2.hour );  print( "-=-=-" );  local dt1 = os.date( "!*t" ); print( dt1.hour );  local dt2 = os.date( "!*t", os.time( dt1 ) ); print( dt2.hour );  local dt2 = os.date( "*t", os.time( dt1 ) ); print( dt2.hour ); 

which yields output:

12 12 -=-=- 10 9 11 

so, in second part, after obtaining timestamp using os.time( os.date( "!*t" ) ); don't know how obtain original date back. i'm doing wrong?

working "date tables" in lua

let dt "date table".
example, value returned os.date("*t") "date table".


how normalize "date table"
example, after adding 1.5 hours current time
local dt = os.date("*t"); dt.min = dt.min + 90
need normalize table fields.

function normalize_date_table(dt)    return os.date("*t", os.time(dt)) end 

this function returns new date table equivalent argument dt regardless of meaning of content of dt: whether contains local or gmt time.


how convert unix time "local date table"

dt = os.date("*t", ux_time) 

how convert unix time "gmt date table"

dt = os.date("!*t", ux_time) 

how convert "local date table" unix time

ux_time = os.time(dt) 

how convert "gmt date table" unix time

-- conversion need precalculated value "zone_diff" local tmp_time = os.time() local d1 = os.date("*t",  tmp_time) local d2 = os.date("!*t", tmp_time) d1.isdst = false local zone_diff = os.difftime(os.time(d1), os.time(d2)) -- zone_diff value may calculated once (at beginning of program)  -- can perform conversion (dt -> ux_time): dt.sec = dt.sec + zone_diff ux_time = os.time(dt) 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -