Created
July 1, 2014 08:24
-
-
Save hehongwei44/a1205e9ff17cfc2359ca to your computer and use it in GitHub Desktop.
页面倒计时的一段运用
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @descition: 倒计时的一段脚本。 | |
* @param:deadline ->截止日期 符合日期格式,比如2012-2-1 2012/2/1等有效日期。 | |
* @return -> 截止的天数、小时、分钟、秒数组成的object对象。 | |
*/ | |
function getCountDown(deadline) { | |
var activeDateObj = {}, | |
currentDate = new Date().getTime(), //获取当前的时间 | |
finalDate = new Date(deadline).getTime(), //获取截止日期 | |
intervaltime = finalDate - currentDate; //有效期时间戳 | |
/*截止日期到期的话,则不执行下面的逻辑*/ | |
if(intervaltime < 0) { | |
return; | |
} | |
var totalSecond = ~~(intervaltime / 1000), //得到秒数 | |
toDay = ~~(totalSecond / 86400 ), //得到天数 | |
toHour = ~~((totalSecond - toDay * 86400) / 3600), //得到小时 | |
tominute = ~~((totalSecond - toDay * 86400 - toHour * 3600) / 60), //得到分数 | |
toSeconde = ~~(totalSecond - toDay * 86400 - toHour * 3600 -tominute * 60); | |
/*装配obj*/ | |
activeDateObj.day = toDay; | |
activeDateObj.hour = toHour; | |
activeDateObj.minute = tominute; | |
activeDateObj.second = toSeconde; | |
return activeDateObj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very good