本文目录一览:
- 1、帮忙改一个js倒计时代码
- 2、求一个倒计时js代码,非常简单的
- 3、时间倒计时代码
- 4、js倒计时代码
帮忙改一个js倒计时代码
(function(timeleft) {
var minutes = 0,
seconds = 0,
caller = arguments.callee,
timer;
if(--timeleft = 0) {
minutes = Math.floor(timeleft / 60);
seconds = Math.floor(timeleft % 60);
document.all["timer"].innerHTML = "距离结束还有" + minutes + "分" + seconds + "秒";
if (timeleft == 5 * 60) {
alert('注意,还有5分钟!');
}
setTimeout(function() {
caller(timeleft);
}, 1000);
} else {
alert("时间到,结束!");
}
}(3600));
求一个倒计时js代码,非常简单的
逻辑如下:
1、先判断两个时间的时间差,当然如果得到的时间是13位时间戳的话你需要转化一下
2、判断时间够一天显示天数,够一小时显示小时数
相关代码:
//获取时间,时间戳转换,不是则不转
var mydate1 = new Date(parseInt(time1.replace("/Date(", "").replace(")/", "")));
var mydate2 = new Date(parseInt(time2.replace("/Date(", "").replace(")/", "")));
//获取剩余秒数
var timerc =dateDiff(mydate, '2015/05/19 10:00:00') / 1000;
function dateDiff(date1, date2) {
var dt1 = new Date(Date.parse(date1));
var dt2 = new Date(Date.parse(date2));
try {
return Math.round((dt2.getTime() - dt1.getTime()));
}
catch (e) {
return e.message;
}
}
//循环调用倒计时
function add() { //加时函数
--timerc; //时间变量自减1
var day = parseInt(timerc / 86400);
var hour = parseInt((timerc % 86400) / 3600);
var min = parseInt((timerc % 3600) / 60);
var sec = Number(parseInt(timerc % 60 / 10)).toString() + Number(parseInt((timerc % 10))).toString();
if (day 0) { //如果不到5分钟
$("#day").html(day + '天'); //写入天数
$("#hour").html(hour + '时'); //写入小时数
$("#min").html(min + '分'); //写入分钟数
$("#sec").html(sec + '秒'); //写入秒数(两位)
}
else if (hour 0) {
$("#hour").html(hour + '时'); //写入小时数
$("#min").html(min + '分'); //写入分钟数
$("#sec").html(sec + '秒'); //写入秒数(两位)
}
else if (min 0) {
$("#min").html(min + '分'); //写入分钟数
$("#sec").html(sec + '秒'); //写入秒数(两位)
}
else if (sec != '00') {
$("#sec").html(sec + '秒'); //写入秒数(两位)
}
else {
tiao(activity); return true;//时间到0调用函数
}
setTimeout("add()", 1000); //设置1000毫秒以后执行一次本函数
};
望采纳!
时间倒计时代码
html
head
title倒计时/title
body
script language=JavaScript
var now = new Date("11/26/2006 " + 10 + ":" + 30 + ":" + 30);
function GetServerTime()
{
var urodz = new Date("11/30/2006 11:38:33");
now.setTime(now.getTime()+250);
days = (urodz - now) / 1000 / 60 / 60 / 24;
daysRound = Math.floor(days);
hours = (urodz - now) / 1000 / 60 / 60 - (24 * daysRound);
hoursRound = Math.floor(hours);
minutes = (urodz - now) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
minutesRound = Math.floor(minutes);
seconds = (urodz - now) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
secondsRound = Math.round(seconds);
document.getElementById("date").innerHTML = daysRound;
document.getElementById("time").innerHTML = hoursRound + ":" + minutesRound + ":" + secondsRound;
}
setInterval("GetServerTime()",250);
/script
距离********还有span id="date"/span span class="white14b"天/span span id="time"/span
/body
/html
js倒计时代码
html
body
离半夜12点还有span id="hour"/span小时span id="min"/span分
/body
script
function countdown() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
h = 23 - h;
m = 59 - m;
m = checkTime(m)
document.getElementById("hour").innerHTML=h;
document.getElementById("min").innerHTML=m;
}
function checkTime(i) {
if (i10) i = "0" + i;
return i;
}
setInterval("countdown()", 50);
/script
html