Lua时间转化 秒转换为日期

function common:second2DateString(second, withSecond)
	local hms = Split(FxGameMaths:formatSecondsToTime(second), ":")
	local dateStr = ""
	
	local h = tonumber(hms[1])
	if h > 0 then
		if h >= 24 then
			local d = math.floor(h / 24)
			dateStr = d .. FxLanguage:getInstance():getString("@Days")
		end
		dateStr = dateStr .. (h % 24) .. FxLanguage:getInstance():getString("@Hour")
	end
	
	local m = tonumber(hms[2])
	if h > 0 or m > 0 then
		dateStr = dateStr .. m .. FxLanguage:getInstance():getString("@Minute")
	end
	
	if withSecond == nil or withSecond == true or dateStr == "" then
		local s = tonumber(hms[3])
		dateStr = dateStr .. s .. FxLanguage:getInstance():getString("@Second")
	end
	
	return dateStr
end
second,时间为秒,wiTHSecond
local timeStr = common:second2DateString(thisActivityInfo.remainTime, false);--转换为时间函数--秒转换为日期

/**
         * 转换时间
         * @param time 时间(秒)
         * @param type 0(时分秒)  1(06:59:59)
         * @param noSec 是否带秒
         */
        static convertTime(time:number, type:number = 1, noSec:boolean = false):string {
            var day:number = Math.floor(time / 86400);
            var $day:number = day * 86400;
            var hour:number = Math.floor((time - $day) / 3600);
            var $hour:number = hour * 3600;
            var min:number = Math.floor((time - $day - $hour) / 60);
            var $min:number = min * 60;
            var sen:number = Math.round(time - $day - $hour - $min);//四舍五入取整数
            var str:string = "";
            if (type == 0) {
                if (day > 0) {
                    str += day.toString() + LangManager.instance.getText("@Day");
                }
                if (hour > 0) {
                    str += hour.toString() + LangManager.instance.getText("@Hour");
                }
                if (min > 0) {
                    str += min.toString() + LangManager.instance.getText("@Minute");
                }
                if (sen > 0 && !noSec) {
                    str += sen.toString() + LangManager.instance.getText("@Second");
                }
            }
            else if (type == 1) {
                hour += day * 24;
                if (hour > 0) {
                    if (hour < 10) {
                        str += "0";
                    }
                    str += hour.toString() + ":";
                }
                else {
                    str += "00:";
                }
                if (min > 0) {
                    if (min < 10) {
                        str += "0";
                    }
                    str += min.toString() + ":";
                }
                else {
                    str += "00:";
                }
                if (sen > 0 && !noSec) {
                    if (sen < 10) {
                        str += "0";
                    }
                    str += sen.toString();
                }
                else {
                    str += "00";
                }
            }
            return str;
        }


你可能感兴趣的:(Lua,C/C++,Egret,Egret,TypeScript,JavaScript)