functiontimediff(long_time, short_time, return_type)
return_type = return_type or'day'local otab = os.date("*t", short_time)
local ntab = os.date("*t", long_time)
local temp = { 1, 12, 30 }
local res = 0for i, name inipairs({ 'year', 'month' }) do
res = res * temp[i] + (ntab[name] - otab[name])
if name == return_type thenreturn res
endendif return_type == 'day'thenlocal n_day
local days = 0for i = 1, res dolocal t_m = otab.month + (i - 1)
local t_y = otab.year + math.modf((t_m - 1) / 12)
t_m = t_m % 12 == 0and12or t_m % 12
days = days + getDaysWithMonth(t_m, t_y)
end
res = days + ntab['day'] - otab['day']
return res
end--处理 小时、分钟、秒local temp = { 24, 60, 60 }
for i, name inipairs({ 'hour', 'min', 'sec' }) do
res = res * temp[i] + (ntab[name] - otab[name])
if name == return_type thenreturn res
endendend