Lua笔记记录


--时间格式说明
如果字段 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))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

willgon123

谢谢打赏,我将再接再厉!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值