Skip to content

Instantly share code, notes, and snippets.

@tkuchiki
Last active Aug 15, 2019
Embed
What would you like to do?
[Openresty] %z だと nginx の iso_8601 の format と異なるので(: がない)、format を揃える
now = os.time()
offset = os.difftime(os.time(os.date("*t", now)), os.time(os.date("!*t", now)))
hour = math.floor(offset / 3600)
min = (offset / 60) % 60
timezone = nil
if offset < 0 then
timezone = string.format("-%02d:%02d", hour, min)
else
timezone = string.format("+%02d:%02d", hour, min)
end
ngx.say(os.date("%Y-%m-%dT%T", ngx.req.start_time()) .. timezone)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment