cocos 时间函数需要什么引用_cocos creator 游戏中常用的2位有效时间整合函数

//时间函数1

function getTime(mss, ptype) {

let type = ptype || 1

let dayName

let hourName

let minuteName

let secondName

if (type == 1) {

dayName = "天"

hourName = "时"

minuteName = "分"

secondName = "秒"

} else if (type == 2) {

dayName = ":"

hourName = ":"

minuteName = ":"

secondName = ""

} else {

return "type 不正确 请检查参数"

}

var days = parseInt(mss / (1000 * 60 * 60 * 24));

var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));

var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));

var seconds = (mss % (1000 * 60)) / 1000;

// cc.log(days)

// cc.log(hours)

// cc.log(minutes)

// cc.log(seconds)

if (days > 0) {

//cc.log("X天X小时")

return days + dayName + hours + hourName

} else if (hours > 0) {

//cc.log("X时X分")

return hours + hourName + minutes + minuteName

} else if (minutes > 0) {

//cc.log("X分X秒")

return minutes + minuteName + seconds + secondName

} else if (seconds > 0) {

//cc.log("X秒")

return seconds + secondName

}

cc.log("时间已经为负数 显示 0秒 或者返回 null")

return "0" + secondName//days + dayName + hours + hourName + minutes + minuteName + seconds + secondName;

}

window.g_getTime = getTime

//倒计时

let time = 1000 * 60 * 60//Date.now();

var self = this

this.schedule(function() {

// 这里的 this 指向 component

//

time = time - 1000

this.timeLabel.string = g_getTime(time, 2)

}, 1);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值