获得前一天的日期的函数
1 function day_step(old_day,step) 2 local y,m,d 3 if("0" ~= string.sub(old_day,6,6)) then 4 m=string.sub(old_day,6,7) 5 else 6 m=string.sub(old_day,7,7) 7 end 8 9 if("0" ~= string.sub(old_day,9,9)) then 10 d=string.sub(old_day,9,10) 11 else 12 d=string.sub(old_day,10,10) 13 end 14 15 y=string.sub(old_day,0,4) 16 17 local old_time=os.time{year=y,month=m,day=d} 18 local new_time=old_time+86400*step 19 20 local new_day=os.date("*t",new_time) 21 local res="" 22 23 if(tonumber(new_day.day)<10 and tonumber(new_day.month)<10)then 24 res=new_day.year.."-".."0"..new_day.month.."-".."0"..new_day.day 25 elseif tonumber(new_day.month)<10 then 26 res=new_day.year.."-".."0"..new_day.month.."-"..new_day.day 27 28 elseif tonumber(new_day.day)<10 then 29 res=new_day.year.."-"..new_day.month.."-".."0"..new_day.day 30 else 31 res=new_day.year.."-"..new_day.month.."-"..new_day.day 32 end 33 return res 34 end
day_step("2013-06-04",-1) -输出-> "2013-06-03"