--时间格式说明
如果字段 b.CreateTime=[2017-02-01 12:23:34]
那么相当于: local CreateTime = { Year=2017, Month=2, Day=1, Hour=12, Min=23, Sec=34 }
相同获取方式:
local year = CreateTime.Year
local month = CreateTime.Month
local day = CreateTime.Day
--获取当前时间Table值
local nowTime1 = { year = os.date("%Y"), month = os.date("%m"), day = os.date("%d"), hour = os.date("%H"), min = os.date("%M"), sec = os.date("%S") }
--获取当前时间时间值(Table值转时间值)
local nowTime2 = os.time( nowTime1 )
--获取当前时间的字符串(Table值转时间值转字符串)
local nowTime3 = os.date("%Y-%m-%d %H:%M:%S",os.time( nowTime1 ))
--获取某字段时间值(时间取值为大写开头)
local newRelativeDate = os.time({ year = b.CreateDate.Year, month = b.CreateDate.Month, day = b.CreateDate.Day, hour = 0, min = 0, sec = 0})
--计算某月有多少天
local dateTime={ year = 2017, month = 2, day = 1 }
return os.date("%d",os.time({ year=dateTime.year, month=dateTime.month+1, day=0}))
--时间加减
local newTime = AddMonths(newDate, DiffMonths(b.BillDate, b.CreateDate)+1)
local newTime = AddDays(newDate, 10)
--if-else判断逻辑(注意"then"和"end"位置)
function GetFixDeductPlatform(bus,toAccount,instruction)
if(bus.ProductType==27) then
return ConstDeductPlatform.HeBao
elseif(bus.ProductType==31) then
return ConstDeductPlatform.GouJiBao
else
return nil
end
end
--三元运算符
function mcompare(a,b)
return ( a>b and a ) or b
end
--数组是否包含值
function ListContain(list,val)
if not list then
return false
end
if list then
for k,v in pairs(list) do
if v==val then
return true
end
end
end
end
--调用方法
GetOtherFunc(a,NewFunc) --调用其他方法
function GetOtherFunc(A,func) --定义使用方法
return func(A) --调用方法
end
function NewFunc(A) --实际调用方法
return A.Name
end
--数字截取
tonumber(string.sub(""2018年12月21日"",0,4))