Lua   发布时间:2022-04-12  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了几个函数大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
--
--常用公共函数库
--
local FUNC = {}

--to int
FUNC.int = function(sString)
    local iNum = tonumber(sString)
    iNum = ((iNum == nil) and tonumber(0)) or iNum
    return iNum
end


--将字符串分割成数组,同php: explode
FUNC.explode = function(szFullString,szSeparator)  
    local nFindStarTindex = 1  
    local nSpliTindex = 1  
    local nSplitArray = {}  
    while true do  
        local nFindLasTindex = String.find(szFullString,szSeparator,nFindStarTindeX)  
        if not nFindLasTindex then  
            nSplitArraY[nSpliTindex] = String.sub(szFullString,nFindStarTindex,String.len(szFullString))  
            break  
        end  
        nSplitArraY[nSpliTindex] = String.sub(szFullString,nFindLasTindex - 1)  
        nFindStarTindex = nFindLasTindex + String.len(szSeparator)  
        nSpliTindex = nSpliTindex + 1  
    end  
    return nSplitArray  
end  

--将日期转换为时间戳,date(Y-m-d H:i:s) 同php strtotime,只支持 1970-01-01 08:00:00 格式
--返回时间戳
FUNC.strtotime = function(sDatE)
    local iTime = 0
    
    if 0 == String.len(sDatE) then 
        return iTime
    end
    local sDateymd = String.sub(sDate,1,10)
    local sDatehis = String.sub(sDate,12,-1)
    local aDateymd = FUNC.explode(sDateymd,'-')
    local aDatehis = FUNC.explode(sDatehis,':')
    local Y,m,d = aDateymd[1],aDateymd[2],aDateymd[3]
    local H,i,s = aDatehis[1],aDatehis[2],aDatehis[3]
    iTime = os.time({year=Y,month=m,day=d,hour=H,min=i,sec=s})
    return iTime
end

return FUNC

大佬总结

以上是大佬教程为你收集整理的几个函数全部内容,希望文章能够帮你解决几个函数所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: