Skip to content

Instantly share code, notes, and snippets.

@ichramm
Created May 29, 2013 22:17
Show Gist options
  • Save ichramm/5674287 to your computer and use it in GitHub Desktop.
Save ichramm/5674287 to your computer and use it in GitHub Desktop.
Lua function that returns the current time in UTC.
--[[!
-- @return The current time in UTC
--]]
function gmtime()
return os.time(os.date("!*t"));
end
@Mons
Copy link

Mons commented Nov 12, 2017

This is wrong.
Epoch time is the same for every timezone.
But this calculates shifted epoch time.
Correct usages are:

os.time() - get current epoch value
os.time{ ... } - get epoch value for local date/time values
os.date("*t"),os.date("%format") - get your local date/time
os.date("!*t") or os.date("!%format") - get GMT date/time
os.date("*t", timestamp),os.date("%format", timestamp) - get your local date/time for given timestamp
os.date("!*t", timestamp) or os.date("!%format", timestamp) - get GMT date/time for given timestamp

This response was written just because this gist appears by "lua date gmt" search query ;)

@hylexus
Copy link

hylexus commented Apr 23, 2018

is there any way to get time from redis server (version <= 3.2) with lua script ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment