js倒计时一
html代码:
<script language="javascript" type="text/javascript">
function djs(){
var urodz= new date("11/12/2008");
var now = new date();
var num
var ile = urodz.gettime() - now.gettime();
var dni = math.floor(ile / (1000 * 60 * 60 * 24));
if (dni >1)
num=dni+1
else if (dni == 1) num=2
else if (dni == 0) num=1
else num=0
document.write(num)
}
</script>
代码二
<script language="javascript">
<!-- begin
var timedate= new date("january 14,2006");
var times="研究生考试";
var now = new date();
var date = timedate.gettime() - now.gettime();
var time = math.floor(date / (1000 * 60 * 60 * 24));
if (time >= 0) ;
document.write("<li><font color=#dedbde>现在离2006年"+times+"还有: <font color=#ffffff><b>"+time +"</b></font> 天</font></li>");
// end -->
</script>
倒计时三
<script language="javascript" type="text/javascript">
var interval = 1000;
function showcountdown(year, month, day, divname) {
var now = new date();
var enddate = new date(year, month - 1, day, 14, 07);
var lefttime = enddate.gettime() - now.gettime();
var leftsecond = parseint(lefttime / 1000);
var day1 = math.floor(leftsecond / (60 * 60 * 24));
var hour1 = math.floor((leftsecond - day1 * 24 * 60 * 60) / 3600);
var hour = math.floor((leftsecond - 60 * 60) / 3600);
//如果小时为负数 显示0
if (hour > 0) {
}
else {
hour = 0;
}
if (day1 < 0) {
hour = hour1
}
var minute = math.floor((leftsecond - day1 * 24 * 60 * 60 - hour1 * 3600) / 60);
var second = math.floor(leftsecond - day1 * 24 * 60 * 60 - hour1 * 3600 - minute * 60);
var cc = document.getelementbyid(divname);
//如果结束时间为负数 就显示0
if (lefttime > 0) {
cc.innerhtml = hour + "小时" + minute + "分" + second + "秒";
//如果显示年份 取消注释
//cc.innerhtml = "距离" + year + "年" + month + "月" + day + "日还有:" + hour + "小时" + minute + "分" + second + "秒";
}
else {
cc.innerhtml = 0 + "小时" + 0 + "分" + 0 + "秒";
}
}
//showdata是div的id 2010,8,10表示是年月日的意思 参数根据自己的需求设置。
window.setinterval(function () { showcountdown(2010, 8, 10, 'showdata'); }, interval);
</script>
想要哪里显示倒计时
<div id="showdata">
</div>