第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

js實(shí)現(xiàn)一個(gè)倒計(jì)時(shí)處理問題

js實(shí)現(xiàn)一個(gè)倒計(jì)時(shí)處理問題

不負(fù)相思意 2019-05-21 17:17:33
實(shí)現(xiàn)一個(gè)功能:以小時(shí)計(jì)算,如活動(dòng)到期時(shí)間為'20:30:50',以當(dāng)前的時(shí)間考試計(jì)算離到達(dá)目標(biāo)是時(shí)間剩余多少‘小時(shí):分:秒’的功能。我的初步代碼是:setTime(){constcurrentTime=newDate();constarr=this.props.data.aimTime.split(':');//輸入字符串格式的時(shí)間格式,如:'20:30:45'constaimTime=3600000*(parseInt(arr[0]))+60000*(parseInt(arr[1]))+1000*(parseInt(arr[2]));//計(jì)算目標(biāo)時(shí)間毫秒數(shù)constcuTime=(3600000*currentTime.getHours())+(60000*currentTime.getMinutes())+(1000*currentTime.getSeconds());//當(dāng)前時(shí)間毫秒數(shù)constremainTime=aimTime-cuTime;//一天內(nèi)離目標(biāo)時(shí)間剩余毫秒數(shù)consthours=parseInt(arr[0])-currentTime.getHours();//剩余小時(shí)constmin=parseInt(arr[1])>0?(60-currentTime.getMinutes()+parseInt(arr[1])):60-currentTime.getMinutes();//剩余分鐘,有問題感覺constsecond=parseInt(arr[2])>0?(60-currentTime.getSeconds()+parseInt(arr[2])):60-currentTime.getSeconds();//剩余秒,有問題感覺remainTime>0&&this.setState({hours:hours>9?hours:'0'+hours,min:min>9?min:'0'+min,second:second>9?second:'0'+second,});}這樣寫分鐘和秒數(shù)不正確,該如何更正,或者有什么更好的方式實(shí)現(xiàn)這一功能
查看完整描述

2 回答

?
喵喔喔

TA貢獻(xiàn)1735條經(jīng)驗(yàn) 獲得超5個(gè)贊

舉個(gè)栗子:當(dāng)前時(shí)間09:01:01,目標(biāo)時(shí)間10:59:59按照你的計(jì)算方法,剩余秒數(shù)和分鐘數(shù)是會(huì)超過60的。但是超過60,在數(shù)學(xué)上應(yīng)該進(jìn)位的,你少了進(jìn)位操作。
再舉個(gè)栗子,十進(jìn)制里面,計(jì)算減法計(jì)算,是個(gè)、十、百分開計(jì)算的么?
附上自己的代碼:
consthours=parseInt(remainTime/3600/1000);//剩余小時(shí)
constmin=parseInt((remainTime-(hours*3600*1000))/60/1000);//剩余分鐘
constsecond=parseInt((remainTime-(hours*3600*1000)-(min*60*1000))/1000);//剩余秒
                            
查看完整回答
反對(duì) 回復(fù) 2019-05-21
  • 2 回答
  • 0 關(guān)注
  • 426 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)