在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
--根据日期获取星期几 function getWeekNum(strDate) local ymd = Split(strDate,"-") t = os.time({year=tostring(ymd[1]),month=tostring(ymd[2]),day=tostring(ymd[3])}) local weekNum = os.date("*t",t).wday -1 if weekNum == 0 then weekNum = 7 end return weekNum end ngx.say(getWeekNum("2018-04-25"))
--根据一个日期获取下几天,dayChange参数为下几天 function getNextDay(strDate,dayChange) local _startDate = Split(startDate,"-") local time=os.time({year=tostring(_startDate[1]), month=tostring(_startDate[2]), day=tostring(_startDate[3])})+dayChange*86400 --一天86400秒 return (os.date('%Y',time).."-"..os.date('%m',time).."-"..os.date('%d',time)) end ngx.say(getNextDay("2018-04-25", 1))
--计算一个时间段中有几天 function getDays(startDate, endDate) local startDateTab = Split(startDate,"-") local endDateTab = Split(endDate,"-") numDay1 = os.time({year=tostring(startDateTab[1]), month=tostring(startDateTab[2]), day=tostring(startDateTab[3])}) numDay2 = os.time({year=tostring(endDateTab[1]), month=tostring(endDateTab[2]), day=tostring(endDateTab[3])}) return (numDay1-numDay2)/(3600*24)+1; end ngx.say(getDays("2018-04-25", "2018-04-20"))
--遍历一个值是否在数组中 function IsInTable(value, tbl) for k,v in ipairs(tbl) do if v == value then return true; end end return false; end
--获取前10分钟 ngx.print(os.date("%Y%m%d%H%M%S",os.time()-600))
|
请发表评论