lua获取当前时间戳:os.time()
如果要获取指定时间(如:2018-8-14 20:28:42)的Unix时间戳,可以参考下面的方法
local function time2unixStamp(timeString)
timeString = timeString.gsub(timeString.gsub(timeString, ' ', '-'), ':', '-')
local t = {}
local reps = '-'
string.gsub(timeString, '[^' .. reps .. ']+', function(w)
table.insert(t, w)
end)
return os.time({ year = t[1], month = t[2], day = t[3], hour = t[4], min = t[5], sec = t[6] })
end
time2unixStamp("2018-8-14 20:28:42") --> 1534249722