/**
* 倒计时
* countDown('2017-8-11 24:0:0') -> 剩余0天0小时54分钟41秒
* @param {Date} endTime 结束时间
* @return {[type]} [description]
*/
countDown (endTime) {
let start = new Date()
let end = new Date(endTime)
let dif = end.getTime() - start.getTime()
let d = 0
let h = 0
let m = 0
let s = 0
if (dif >= 0) {
d = Math.floor(dif / 1000 / 3600 / 24)
h = Math.floor(dif / 1000 / 60 / 60 % 24)
m = Math.floor(dif / 1000 / 60 % 60)
s = Math.floor(dif / 1000 % 60)
}
return `仅剩${d}天${h}小时${m}分钟${s}秒`
}
更多布局来自百度:职业生涯前端存储库