一个lua的简单日期格式化

Posted avi9111

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一个lua的简单日期格式化相关的知识,希望对你有一定的参考价值。

格式化

local seconds = 65    
local day = math.floor(seconds / 86400)
    seconds = math.fmod(seconds, 86400)
    local hour = math.floor(seconds / 3600)
    seconds = math.fmod(seconds, 3600)
    local min = math.floor(seconds / 60)
    local sec = math.fmod(seconds, 60)
    if day > 0 then
        return string.format("%02d:%02d:%02d:%02d", day, hour, min, sec)
    else
        return string.format("%02d:%02d:%02d", hour, min, sec);
    end

倒数实现

    self.maxMatchCd = 65
     coroutine.start(function()
          local currCd = self.maxMatchCd
          self.forceStopMatchCD = false
          while true do
               coroutine.waitforseconds(1);    
               currCd = currCd -1
               -- do somthing with param:currCd
               if self.forceStopMatchCD  then
                    
                    break
               end
          end


     end)

倒数暂停

self.forceStopMatchCD = true;

以上是关于一个lua的简单日期格式化的主要内容,如果未能解决你的问题,请参考以下文章