Skip to content

Instantly share code, notes, and snippets.

@hehongwei44
Created July 1, 2014 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hehongwei44/a1205e9ff17cfc2359ca to your computer and use it in GitHub Desktop.
Save hehongwei44/a1205e9ff17cfc2359ca to your computer and use it in GitHub Desktop.
页面倒计时的一段运用
/**
*
* @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;
}
@luoyeyeyu
Copy link

very good

@CooLNuanfeng
Copy link

要怎么使用啊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment