在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
-- %a abbreviated weekday name (e.g., Wed) -- 如获取当前年月日时分秒:local date=os.date(“%Y-%m-%d %H:%M:%S”);
local s = os.difftime(currentTime, CoolingTime) local s = os.difftime(currentTime, CoolingTime) ----------------------------获取指定时间值----------------------------- local tab = {year=2005, month=11, day=6, hour=22,min=18,sec=30,isdst=false} -- 获取当前时间的table格式 --year表示年,month表示月,day表示日期,hour表示小时,min表示分钟,sec表示秒,isdst表示是否夏令时 local GameLogic = commonlib.gettable("Pisces.GameLogic") local TimeTool = {} commonlib.TimeTool = TimeTool local HOUR_OF_DAY = 24 local SECOND_OF_MINUTE = 60 local SECOND_OF_HOUR = 3600 local SECOND_OF_DAY = HOUR_OF_DAY * SECOND_OF_HOUR function TimeTool:GetServerUnixTime( ) return GameLogic:GetServerUnixTime() end function TimeTool:GetMillSecond( ) return cc.Director:getMillSecond() end --往前追朔到某一天的零点, 单位秒数 function TimeTool:GetDayBegin(time) time = time or self:GetServerUnixTime() local timetable = os.date("*t", time) timetable.hour=0 timetable.min =0 timetable.sec = 0 return os.time(timetable) end --当前是一天的第几秒 function TimeTool:GetSecondsOfDay( ) local now = self:GetServerUnixTime() local zero = self:GetDayBegin(now) return now - zero end --将秒数转换为:00:00:00 function TimeTool:TimeToString(time, flag) time = time or self:GetServerUnixTime() local sec = time % SECOND_OF_MINUTE local min = math.floor(time / 60) % 60 local hour = math.floor(time / SECOND_OF_HOUR) if flag == 1 then return string.format("%02d:%02d:%02d", hour, min, sec) elseif flag == 2 then return string.format("%02d:%02d", min, sec) end end --获取间隔的天数 function TimeTool:GetIntervalDay(timeBegin, tiemEnd) local dayBegTime1 = self:GetDayBegin(timeBegin) local dayBegTime2 = self:GetDayBegin(tiemEnd) return math.floor((math.abs(dayBegTime2 - dayBegTime1)) / SECOND_OF_DAY) end -- 检查两个时间是否为同一天 function TimeTool:CheckTheSameDay(time1, time2) return self:GetIntervalDay(time1, time2) == 0 end --得到自定义“天”的初始时间点, dayHour, dayMin, daySec为自定义天的跨越点 function TimeTool:GetUserDayBegTime(time, dayHour, dayMin, daySec) time = time or self:GetServerUnixTime() dayHour = dayHour or 0 dayMin = dayMin or 0 daySec = daySec or 0 local tbTime local curHour = tonumber(os.date("%H", time)) if curHour < dayHour then local nTime = time - 60*60*24 tbTime = os.date("*t", nTime) else tbTime = os.date("*t", time) end tbTime.hour = dayHour tbTime.min= dayMin tbTime.sec = daySec return os.time(tbTime) end --判断两个时间是否在同一“天” function TimeTool:DiffUserDay(time1, time2, dayHour, dayMin, daySec) dayHour = dayHour or 0 dayMin = dayMin or 0 daySec = daySec or 0 local DayBegTime1 = self:GetUserDayBegTime(time1, dayHour, dayMin, daySec) local DayBegTime2 = self:GetUserDayBegTime(time2, dayHour, dayMin, daySec) return DayBegTime1 == DayBegTime2 end
|
请发表评论