日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 前端技术 > vue >内容正文

vue

Vue中的时间转换,把毫秒换算成正常时间

發(fā)布時(shí)間:2023/12/20 vue 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Vue中的时间转换,把毫秒换算成正常时间 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一、53200毫秒

只到秒,沒(méi)有分,沒(méi)有進(jìn)位,只要簡(jiǎn)單的除以1000就可以了

{{Math.round(time0/1000)}}

二、3022222毫秒

進(jìn)位到分鐘,需要除以60,然后把小數(shù)點(diǎn)前后部分的數(shù)值分開(kāi)來(lái)處理

{{Math.floor(Math.round(time/1000)/60)}}:{{Math.round(time/1000)%60}}

三、32300432毫秒

進(jìn)位到了小時(shí),需要把除以60得到的整數(shù)部分,再除以60,把得到的數(shù)的小數(shù)和整數(shù)部分分開(kāi)繼續(xù)處理

{{Math.floor(Math.floor(Math.round(time2/1000)/60)/24) }}:{{Math.floor(Math.round(time2/1000)/60)%24 }}:{{Math.round(time2/1000)%60}}

四、4242323234毫秒

分步除以60、60、24,一共要處理四個(gè)數(shù)

{{Math.floor(Math.floor(Math.floor(Math.round(time3/1000)/60)/60)/24)}}天{{Math.floor(Math.floor(Math.round(time3/1000)/60)/60)%24}}時(shí){{Math.floor(Math.round(time3/1000)/60)%60}}分{{Math.round(time3/1000)%60}}秒

顯示結(jié)果:

五、53200毫秒

把第一步的數(shù)和第四步的代碼結(jié)合起來(lái)看看,出來(lái)的是什么結(jié)果

這樣顯示明顯不合適,0的時(shí)候就可以不用顯示

加個(gè)v-show來(lái)做下判斷,代碼就改進(jìn)成下面這樣

給div都加上display: inline-block;改成行內(nèi)塊,讓它們能顯示在同一行

<div><div v-show="time0/1000>86400" style="display: inline-block;">{{Math.floor(Math.floor(Math.floor(Math.round(time0/1000)/60)/60)/24)}}天</div><div v-show="time0/1000>3600" style="display: inline-block;">{{Math.floor(Math.floor(Math.round(time0/1000)/60)/60)%24}}時(shí)</div> <div v-show="time0/1000>60" style="display: inline-block;">{{Math.floor(Math.round(time0/1000)/60)%60}}分</div> {{Math.round(time0/1000)%60}}秒</div>

顯示就正常了

再加個(gè)三目運(yùn)算把個(gè)位數(shù)的前面都拼接上0

然后代碼一下就變得無(wú)比的長(zhǎng)

<div><div v-show="time0/1000>86400" style="display: inline-block;">{{Math.floor(Math.floor(Math.floor(Math.round(time0/1000)/60)/60)/24)<10?('0'+Math.floor(Math.floor(Math.floor(Math.round(time0/1000)/60)/60)/24)):Math.floor(Math.floor(Math.floor(Math.round(time0/1000)/60)/60)/24)}}天</div><div v-show="time0/1000>3600" style="display: inline-block;">{{Math.floor(Math.floor(Math.round(time0/1000)/60)/60)%24<10?('0'+Math.floor(Math.floor(Math.round(time0/1000)/60)/60)%24):Math.floor(Math.floor(Math.round(time0/1000)/60)/60)%24}}時(shí)</div> <div v-show="time0/1000>60" style="display: inline-block;">{{Math.floor(Math.round(time0/1000)/60)%60<10?('0'+Math.floor(Math.round(time0/1000)/60)%60):Math.floor(Math.round(time0/1000)/60)%60}}分</div> {{Math.round(time0/1000)%60<10?('0'+Math.round(time0/1000)%60):Math.round(time0/1000)%60}}秒</div>

顯示效果對(duì)比

重點(diǎn):

%:取余

Math.floor():相當(dāng)于省去小數(shù)后的數(shù)字

Math.round():四舍五入?

總結(jié)

以上是生活随笔為你收集整理的Vue中的时间转换,把毫秒换算成正常时间的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。