Skip to content

Instantly share code, notes, and snippets.

@GZShi
Last active August 29, 2015 14:09
Show Gist options
  • Save GZShi/de30952cbb29099e7adb to your computer and use it in GitHub Desktop.
Save GZShi/de30952cbb29099e7adb to your computer and use it in GitHub Desktop.
定时秒杀
/**
* 1. 更改日期和时间设置
* 2. Internet 时钟
* 3. 更改设置
* 4. time.pool.aliyun.com
* 5. 立即更新
* 6. 确定
*/
/**
* 定时秒杀
* @author LeiFeng
* @param {Number} time 秒杀时间
* @param {Function} todo 秒杀操作
*/
function timeTODO(time, todo) {
var now = Date.now();
if(now >= time) {
todo.call(null);
} else {
setTimeout(timeTODO.bind(null, time, todo), (time-now) >> 1);
}
}
timeTODO(+new Date('2014/11/11 00:00:00'), function () {
// 买!买!买!!!
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment