12.1
#!/usr/bin/lua
function nextmonth(num)
temp=os.date("*t",num)
temp.month=temp.month+1
return os.time(temp)
end
12.2
#!/usr/bin/lua
function wday(num)
result=os.date("%w",num)
return math.floor(result+1)
end
12.3
#!/usr/bin/lua
function dsec(num)
temp=os.date("*t",num)
sum=temp.hour*3600+temp.min*60+temp.sec
return sum
end
12.4
#!/usr/bin/lua
function firstfriday(num) --年用四位记法
temp={year=num,month=1,day=1}
temp=os.date("*t",os.time(temp))
cur=temp.wday
if cur<=6 then
temp.day=temp.day+6-cur
else
temp.day=temp.day+6
end
temp=os.date("*t",os.time(temp))
return temp.yday
end
12.5
#!/usr/bin/lua
function diffday(num1,num2)
return math.floor(os.difftime(num1,num2)//(24*60*60))
end
12.6
#!/usr/bin/lua
function diffmonth(num1,num2)
t1=os.date("*t",num1)
t2=os.date("*t",num2)
mon1=t1.month-t2.month
year1=math.abs(t1.year-t2.year)
mon1=year1*12+mon1
return mon1
end
12.7
#!/usr/bin/lua
t1={year=2021,month=8,day=31}
t1=os.date("*t",os.time(t1))
t2=t1
t1.day=t1.day+1
t1=os.date("*t",os.time(t1))
t1.month=t1.month+1
t1=os.date("*t",os.time(t1))
t2.month=t2.month+1
t2=os.date("*t",os.time(t2))
t2.day=t2.day+1
t2=os.date("*t",os.time(t2))
print(os.date("%c",os.time(t1)))
print(os.date("%c",os.time(t2)))
不同,如果增加的一天导致月份发生变化时。因为每个月的天数不一定相同。
12.8
#!/usr/bin/lua
function zone(num)
return os.date("%z",num)
end