本文目录一览:
JS倒计时页面代码(要求读取服务器时间)
script language="JavaScript"
function setTab(name,cursel,n){
for(i=1;i=n;i++){
var menu=document.getElementById(name+i);
var con=document.getElementById("con_"+name+"_"+i);
menu.className=i==cursel?"hover":"";
con.style.display=i==cursel?"block":"none";
}
}var DifferenceHour = -1
var DifferenceMinute = -1
var DifferenceSecond = -1
var Tday = new Date("Feb 14, 2010 00:00:00") //**倒计时时间点-注意格式
var daysms = 24 * 60 * 60 * 1000
var hoursms = 60 * 60 * 1000
var Secondms = 60 * 1000
var microsecond = 1000function left(mainStr,lngLen) {
if (lngLen0) {return mainStr.substring(0,lngLen)}
else{return null}
}
function right(mainStr,lngLen) { if (mainStr.length-lngLen=0 mainStr.length=0 mainStr.length-lngLen=mainStr.length) {
return mainStr.substring(mainStr.length-lngLen,mainStr.length)}
else{return null}
}
function mid(mainStr,starnum,endnum){
if (mainStr.length=0){
return mainStr.substr(starnum,endnum)
}else{return null} }function clock()
{
var time = new Date()
var hour = time.getHours()
var minute = time.getMinutes()
var second = time.getSeconds()
var timevalue = ""+((hour 12) ? hour-12:hour)
timevalue +=((minute 10) ? ":0":":")+minute
timevalue +=((second 10) ? ":0":":")+second
timevalue +=((hour 12 ) ? " PM":" AM")var convertHour = DifferenceHour
var convertMinute = DifferenceMinute
var convertSecond = DifferenceSecond
var Diffms = Tday.getTime() - time.getTime()
DifferenceHour = Math.floor(Diffms / daysms)
Diffms -= DifferenceHour * daysms
DifferenceMinute = Math.floor(Diffms / hoursms)
Diffms -= DifferenceMinute * hoursms
DifferenceSecond = Math.floor(Diffms / Secondms)
Diffms -= DifferenceSecond * Secondms
var dSecs = Math.floor(Diffms / microsecond)var dd=document.getElementById("dd");
var hh=document.getElementById("hh");
var mm=document.getElementById("mm");
var ss=document.getElementById("ss");ddstr = DifferenceHour.toString();
hhstr = DifferenceMinute.toString();
mmstr = DifferenceSecond.toString();
ssstr = dSecs.toString();if (Tday.getTime() time.getTime()){
if (ddstr.length2){
ddstrs = "span class='num0'/spanspan class='num"+ddstr.substr(0,1)+"'/span";
}else{
ddstrs = "span class='num"+ddstr.substr(0,1)+"'/spanspan class='num"+ddstr.substr(1,2)+"'/span";
}if (hhstr.length2){
hhstrs = "span class='num0'/spanspan class='num"+hhstr.substr(0,1)+"'/span";
}else{
hhstrs = "span class='num"+hhstr.substr(0,1)+"'/spanspan class='num"+hhstr.substr(1,2)+"'/span";
}if (mmstr.length2){
mmstrs = "span class='num0'/spanspan class='num"+mmstr.substr(0,1)+"'/span";
}else{
mmstrs = "span class='num"+mmstr.substr(0,1)+"'/spanspan class='num"+mmstr.substr(1,2)+"'/span";
}if (ssstr.length2){
ssstrs = "span class='num0'/spanspan class='num"+mmstr.substr(0,1)+"'/span";
}else{
ssstrs = "span class='num"+ssstr.substr(0,1)+"'/spanspan class='num"+ssstr.substr(1,2)+"'/span";
}
}else{
ddstrs="span class='num0'/spanspan class='num0'/span"
hhstrs="span class='num0'/spanspan class='num0'/span"
mmstrs="span class='num0'/spanspan class='num0'/span"
ssstrs="span class='num0'/spanspan class='num0'/span"
}if(convertHour != DifferenceHour) dd.innerHTML=ddstrs;
if(convertMinute != DifferenceMinute) hh.innerHTML=hhstrs;
if(convertSecond != DifferenceSecond) mm.innerHTML=mmstrs;
ss.innerHTML=ssstrs;
setTimeout("clock()",1000)}/script 上面的是JS部分的。 下面是HTML部分的。div class="mains"
div class="djs"
div id="dd"/div
div id="tsfm"天/div
div id="hh"/div
div id="tsfm"时/div
div id="mm"/div
div id="tsfm"分/div
div id="ss"/div
div id="tsfm"秒/div
/div 我上面的JS部分的数字全部是用的图片格式显示倒计时数字的哈,你也可以自己改成数字。 好了,上面的代码全部是我之前给客户写的一个春节倒计时贺卡的程序页面,纯原创,并且一直在用,所以是没有任何问题的,你自己应该懂一些技术吧,所以上面的代码你应该看的懂,很简单的。 就不要再追问了,自己多下下功夫研究下,因为最近比较忙,不见得有时间回复,见谅。记得给我分哈,要升级这个号的级别,以后好推广用,谢谢了。
JS 倒计时实现代码(时、分,秒)
JS实现倒计时(时、分,秒)
var
interval
=
1000;
function
ShowCountDown(year,month,day,divname)
{
var
now
=
new
Date();
var
endDate
=
new
Date(year,
month-1,
day);
var
leftTime=endDate.getTime()-now.getTime();
var
leftsecond
=
parseInt(leftTime/1000);
//var
day1=parseInt(leftsecond/(24*60*60*6));
var
day1=Math.floor(leftsecond/(60*60*24));
var
hour=Math.floor((leftsecond-day1*24*60*60)/3600);
var
minute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60);
var
second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60);
var
cc
=
document.getElementById(divname);
cc.innerHTML
=
"脚本之家提示距离"+year+"年"+month+"月"+day+"日还有:"+day1+"天"+hour+"小时"+minute+"分"+second+"秒";
}
window.setInterval(function(){ShowCountDown(2010,4,20,'divdown1');},
interval);
[Ctrl+A
全选
注:如需引入外部Js需刷新才能执行]
求一个倒计时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毫秒以后执行一次本函数
};
望采纳!