Here is what Lua code is adapted from some C code found by Google. It does not handle time slots or daylight saving time, so the outputs relate to universal coordinated time (UTC).
-- based on http://www.ethernut.de/api/gmtime_8c_source.html local floor=math.floor local DSEC=24*60*60 -- secs in a day local YSEC=365*DSEC -- secs in a year local LSEC=YSEC+DSEC -- secs in a leap year local FSEC=4*YSEC+DSEC -- secs in a 4-year interval local BASE_DOW=4 -- 1970-01-01 was a Thursday local BASE_YEAR=1970 -- 1970 is the base year local _days={ -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364 } local _lpdays={} for i=1,2 do _lpdays[i]=_days[i] end for i=3,13 do _lpdays[i]=_days[i]+1 end function gmtime(t) print(os.date("!\n%c\t%j",t),t) local y,j,m,d,w,h,n,s local mdays=_days s=t -- First calculate the number of four-year-interval, so calculation -- of leap year will be simple. Btw, because 2000 IS a leap year and -- 2100 is out of range, this formula is so simple. y=floor(s/FSEC) s=sy*FSEC y=y*4+BASE_YEAR -- 1970, 1974, 1978, ... if s>=YSEC then y=y+1 -- 1971, 1975, 1979,... s=s-YSEC if s>=YSEC then y=y+1 -- 1972, 1976, 1980,... (leap years!) s=s-YSEC if s>=LSEC then y=y+1 -- 1971, 1975, 1979,... s=s-LSEC else -- leap year mdays=_lpdays end end end j=floor(s/DSEC) s=sj*DSEC local m=1 while mdays[m]<j do m=m+1 end m=m-1 local d=j-mdays[m] -- Calculate day of week. Sunday is 0 w=(floor(t/DSEC)+BASE_DOW)%7 -- Calculate the time of day from the remaining seconds h=floor(s/3600) s=sh*3600 n=floor(s/60) s=sn*60 print("y","j","m","d","w","h","n","s") print(y,j+1,m,d,w,h,n,s) end local t=os.time() gmtime(t) t=os.time{year=1970, month=1, day=1, hour=0} gmtime(t) t=os.time{year=1970, month=1, day=3, hour=0} gmtime(t) t=os.time{year=1970, month=1, day=2, hour=23-3, min=59, sec=59} gmtime(t)