【全网最短】实现倒计时:时分秒的功能
生活随笔
收集整理的這篇文章主要介紹了
【全网最短】实现倒计时:时分秒的功能
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
//計(jì)算時(shí)間差毫秒數(shù)
let t = Math.abs(new Date("2022-02-25 23:00:00") - new Date());//倒計(jì)時(shí)格式:天時(shí)分秒毫秒
let t1 = `${parseInt(t / 86400000)}天${parseInt(t / 3600000 % 24)}時(shí)${parseInt(t / 60000 % 60)}分${parseInt(t / 1000 % 60)}秒${parseInt(t % 1000)}毫秒`;//倒計(jì)時(shí)格式:00:00:00:00:0000
let t2 = `${parseInt(t / 86400000).toString().padStart(2, "0")}:${parseInt(t / 3600000 % 24).toString().padStart(2, "0")}:${parseInt(t / 60000 % 60)}:${parseInt(t / 1000 % 60).toString().padStart(2, "0")}:${parseInt(t % 1000).toString().padStart(4, "0")}`;console.log("倒計(jì)時(shí):" + t1); //倒計(jì)時(shí):0天2時(shí)27分30秒319毫秒console.log("倒計(jì)時(shí):" + t2); //倒計(jì)時(shí):00:02:27:30:0319
總結(jié)
以上是生活随笔為你收集整理的【全网最短】实现倒计时:时分秒的功能的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 如何安装蓝湖插件支持Photoshop
- 下一篇: 用原生js的postMessage实现i