后端返回時(shí)間格式為 “2022-11-26 19:07:45”
由于業(yè)務(wù)需要我這里顯示倒計(jì)時(shí)效果,需要時(shí)間戳和本地時(shí)間進(jìn)行計(jì)算。
具體實(shí)現(xiàn)效果:

時(shí)間字符串轉(zhuǎn)時(shí)間戳在安卓端正常,在蘋果端出現(xiàn)轉(zhuǎn)換異常。(小程序,APP端沒(méi)有試驗(yàn))
蘋果端時(shí)間字符為“2022/12/02 10:32:10” 的時(shí)候才能轉(zhuǎn)成時(shí)間戳。
安卓端都支持。
var timeStr = "2022-12-02 10:32:10"
//正則
var resData = timeStr.replace(/-/g, '/')
/// (new Date(resData)).getTime() 就可以將時(shí)間字符串轉(zhuǎn)換成時(shí)間戳
// 下面就是獲取當(dāng)前時(shí)間戳以及,創(chuàng)建時(shí)間加上(天數(shù) X 3600 X 1000)得到結(jié)束時(shí)間戳
let newTime = new Date().getTime();
let endTime = (new Date(resData)).getTime() + (1 * 3600 * 1000 )
let t = endTime - newTime;
// 方法是接收秒級(jí)時(shí)間戳
this.countDown(t / 1000);倒計(jì)時(shí)的顯示和方法倒計(jì)時(shí) {{ time.h || '00' }} :
{{ time.m || '00' }} :
{{ time.s || '00' }} // 變量
let timer = null;
export default { data() { return {time: {h:0,
m:0,
s:0
},
}
}
}
// 倒計(jì)時(shí)
countDown(t) { const that = this;
timer = setInterval(() =>{if (t >0) {// that.time = that.$tools.format(t);
that.time = that.format(t);
t--;
} else {this.grouponStatus = 'end'
clearInterval(timer);
that.time = false;
}
}, 1000);
},
format(t) { let format = {d: '00',
h: '00',
m: '00',
s: '00'
};
if (t >0) {let d = Math.floor(t / 86400);
let h = Math.floor((t / 3600) % 24);
let m = Math.floor((t / 60) % 60);
let s = Math.floor(t % 60);
format.d = d< 10 ? '0' + d : d;
format.h = h< 10 ? '0' + h : h;
format.m = m< 10 ? '0' + m : m;
format.s = s< 10 ? '0' + s : s;
}
return format;
},
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧
本文名稱:記錄時(shí)間字符轉(zhuǎn)時(shí)間戳(小程序蘋果端)會(huì)出現(xiàn)問(wèn)題-創(chuàng)新互聯(lián)
當(dāng)前URL:http://chinadenli.net/article12/hpgdc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、網(wǎng)站排名、網(wǎng)站建設(shè)、網(wǎng)站內(nèi)鏈、App設(shè)計(jì)、網(wǎng)站導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容