题
我是新手,需要你的帮助。在找出几天,小时,分钟和秒的问题上有问题。我不知道在几秒钟后达到几分钟,与小时和天相同。
我正在尝试以天/小时/分钟/秒的格式倒计时。
到目前为止我所做的是什么。
THNX提前!:)
解决方案
我已修改生成的count_execution
函数并添加了一些评论。它应该做你所要求的。
function count_execution() {
// target date of event
var eventDate = new Date(settings.date);
// now
var currentDate = new Date();
// get date diff *in milliseconds*
var diff = Math.abs(currentDate - eventDate);
// compute days left
// 24h * 60m * 60s * 1000 = 86400000
var days = Math.floor(diff / 86400000);
diff = diff % 86400000;
// compute hours left
// 60m * 60s * 1000 = 3600000
var hours = Math.floor(diff / 3600000);
diff = diff % 3600000;
// the same for minutes
var minutes = Math.floor(diff / 60000);
diff = diff % 60000;
// finally, seconds
var seconds = Math.floor(diff / 1000);
$this.find('#days').text(days);
$this.find('#hours').text(hours);
$this.find('#mins').text(minutes);
$this.find('#secs').text(seconds);
}
.
希望它有所帮助。
其他提示
var seconds = 1355998990 - new Date().getTime(), // whatever
minutes = Math.floor(seconds/60),
hours = Math.floor(minutes/60),
days = Math.floor(hours/24);
seconds %= 60;
minutes %= 60;
hours %= 24;
console.log("d: " + days + " h: " + hours + " m: " + minutes + " s: " + seconds);
.
这会做吗?
还确保签出这个;也许你可以在那里得到一些启发。
为什么您不使用可用于执行技巧的众多插件之一,请考虑以下链接:
http://keith-wood.name/countdown.html
这个是列出了许多插件的同一目的,使用它们中的任何一个,微笑:) http://www.tripwiremagazine.com/2012/01/jquery-countdown-scripts.html
不隶属于 StackOverflow