lua中写一个函数 随便输入一个日期时间戳 通过函数判断是不是属于当天的日期,该怎么写?
1个回答
展开全部
function isToday(timestamp)
local today = os.date("*t")
local secondOfToday = os.time({day=today.day, month=today.month,
year=today.year, hour=0, minute=0, second=0})
if timestamp >= secondOfToday and timestamp < secondOfToday + 24 * 60 * 60 then
return true
else
return false
end
end
print(isToday(os.time({day=17, month=5, year=2012, hour=0, minute=0, second=0})))
print(isToday(os.time({day=17, month=5, year=2012, hour=16, minute=28, second=38})))
print(isToday(os.time({day=17, month=5, year=2012, hour=23, minute=59, second=59})))
print(isToday(os.time({day=16, month=5, year=2012, hour=23, minute=59, second=59})))
print(isToday(os.time({day=18, month=5, year=2012, hour=0, minute=0, second=0})))
local today = os.date("*t")
local secondOfToday = os.time({day=today.day, month=today.month,
year=today.year, hour=0, minute=0, second=0})
if timestamp >= secondOfToday and timestamp < secondOfToday + 24 * 60 * 60 then
return true
else
return false
end
end
print(isToday(os.time({day=17, month=5, year=2012, hour=0, minute=0, second=0})))
print(isToday(os.time({day=17, month=5, year=2012, hour=16, minute=28, second=38})))
print(isToday(os.time({day=17, month=5, year=2012, hour=23, minute=59, second=59})))
print(isToday(os.time({day=16, month=5, year=2012, hour=23, minute=59, second=59})))
print(isToday(os.time({day=18, month=5, year=2012, hour=0, minute=0, second=0})))
来自:求助得到的回答
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询