//時間函數(shù)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 不正確 請檢查參數(shù)"
}
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("時間已經(jīng)為負數(shù) 顯示 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);
最后編輯于 :2019.04.15 17:10:31
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者 【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。 平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。