Javascript中的倒计时类
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Javascript中的倒计时类相关的知识,希望对你有一定的参考价值。
A simple countDown class in javascript:
/** * CountDown Class * * @author Giovambattista Fazioli * @email [email protected] * @web http://www.undolog.com * * @param dd (string) 'month day, year' * */ function countDown( dd ) { // init target time var target = new Date( dd ); this.targetTime = target.getTime(); /** * refresh countdown */ this.refresh = function() { var today = new Date(); var currentTime = today.getTime(); // time left this._leftMilliseconds = (this.targetTime - currentTime); this._leftSeconds = Math.floor( this._leftMilliseconds / 1000 ); this._leftMinutes = Math.floor( this._leftSeconds / 60 ); this._leftHours = Math.floor( this._leftMinutes / 60 ); // no module this.leftDays = Math.floor( this._leftHours / 24 ); // for print this.leftMilliseconds = this._leftMilliseconds % 1000; this.leftSeconds = this._leftSeconds % 60; this.leftMinutes = this._leftMinutes % 60; this.leftHours = this._leftHours % 24; } this.refresh(); }
以上是关于Javascript中的倒计时类的主要内容,如果未能解决你的问题,请参考以下文章
JUC并发编程 共享模式之工具 JUC CountdownLatch(倒计时锁) -- CountdownLatch应用(等待多个线程准备完毕( 可以覆盖上次的打印内)等待多个远程调用结束)(代码片段