(1)\将日期时间年-月-日 时-分-秒 转化为 毫秒数
loacl date="2016-08-12 14:34:56"
function getTimeByDate(date)
local a = split(r, " ")
local b = split(a[1], "-")
local c = split(a[2], ":")
local t = os.time({year=b[1],month=b[2],day=b[3], hour=c[1], min=c[2], sec=c[3]})
return t
end
function split(str, pat)
local t = {} -- NOTE: use {n = 0} in Lua-5.0
local fpat = "(.-)" .. pat
local last_end = 1
local s, e, cap = str:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(t,cap)
end
last_end = e+1
s, e, cap = str:find(fpat, last_end)
end
if last_end <= #str then
cap = str:sub(last_end)
table.insert(t, cap)
end
return t
end
(2)将时间毫秒数转换成年月日
loacl seconds="1404955893000"
function formatDate(seconds)
dateformat = "%年%m月%d日 %H:%M:%S"
return os.date(dateformat,tonumber(seconds))
end
以上内容整理来自于网络