Skip to content

Instantly share code, notes, and snippets.

View sunny352's full-sized avatar

MingSailor sunny352

View GitHub Profile
@sunny352
sunny352 / datetime.lua
Last active August 20, 2021 09:35 — forked from zwh8800/datetime.lua
lua ISO 8601 datetime parser - https://repl.it/IQuI/5
function get_timezone()
local now = os.time()
return os.difftime(now, os.time(os.date("!*t", now)))
end
local epoch = get_timezone()
function parse_json_date(json_date)
local year, month, day, hour, minute, seconds, offsetsign, offsethour, offsetmin = json_date:match("(%d+)%-(%d+)%-(%d+)%a(%d+)%:(%d+)%:([%d%.]+)([Z%+%- ])(%d?%d?)%:?(%d?%d?)")
local timestamp = os.time{year = year, month = month, day = day, hour = hour, min = minute, sec = math.floor(seconds)} + epoch
local offset = 0