Getting UTC UNIX timestamp in Lua

The API returns the timestamp as a UNIX timestamp in UTC, and I would like to know if this timestamp was more than a xsecond ago. As expected, this works fine with os.time() - x > timestampin UTC, but explodes in other time zones.

Unfortunately, I cannot find a good way to solve this problem in lua.

os.datehas a prefix !(for example os.date("!%H:%M:%S")) to return the time in UTC, but it seems that despite the fact that it supports all options strftime, it does not support the parameter %s, I heard people mention that this is caused by time parameters compiling Lua for a similar problem, but changing them is not possible because the interpreter is provided by the user.

+4
source share
1 answer

you can use

os.time(os.date("!*t"))

to get the current era of UNIX.

+4
source

Source: https://habr.com/ru/post/1676684/


All Articles