复制别人的,不好意思,稍微修改了一下,多加了注释
<html>
<body>
离2012年还有<b id="show"></b>
<script LANGUAGE="javascript">
startclock();
var timerID = null;
var timerRunning = false;
function showtime() { //倒计时主体部分
Today = new Date();//以下为提取时间
var NowHour = Today.getHours();
var NowMinute = Today.getMinutes();
var NowMonth = Today.getMonth();
var NowDate = Today.getDate();
var NowYear = Today.getYear();
var NowSecond = Today.getSeconds();
if (NowYear <2000)
NowYear=1900+NowYear;
Today = null;
Hourleft = 23 - NowHour //计算剩余小时数
Minuteleft = 59 - NowMinute //计算剩余分钟数
Secondleft = 59 - NowSecond //计算剩余秒数
Yearleft = 2011 - NowYear //计算剩余年数
Monthleft = 12 - NowMonth - 1//计算剩余月数
Dateleft = 31 - NowDate //计算剩余天数
/**
* 上述赋值,表示的就是距离2012年1月1日0点0分0秒的剩余时间数,修改此赋值公式即可得到新的剩余时间
* 例如,距离2012年1月10日0点0分0秒?我将23,59,59,2011,12,31修改为23,59,59,2012,1,9;
* 修改此项的时候,不要忘记修改html文本中的“离2012年还有”;
*/
if (Secondleft<0)
{
Secondleft=60+Secondleft;
Minuteleft=Minuteleft-1;
}
if (Minuteleft<0)
{
Minuteleft=60+Minuteleft;
Hourleft=Hourleft-1;
}
if (Hourleft<0)
{
Hourleft=24+Hourleft;
Dateleft=Dateleft-1;
}
if (Dateleft<0)
{
Dateleft=31+Dateleft;
Monthleft=Monthleft-1;
}
if (Monthleft<0)
{
Monthleft=12+Monthleft;
Yearleft=Yearleft-1;
}
Temp=Yearleft+'年, '+Monthleft+'月, '+Dateleft+'天, '+Hourleft+'小时, '+Minuteleft+'分, '+Secondleft+'秒'
/**你的要求中显示的是天时分,那么你可以在此处将你不需要显示的变量在Temp的赋值中删去**/
document.getElementById('show').innerHTML = Temp;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
var timerID = null;
var timerRunning = false;
function stopclock () {
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function startclock () { //从这里开始执行;并且调用其他两个方法开始倒计时工作
stopclock();
showtime();
}
// -->
</script>
</body>
</html>
B. js倒计时代码还剩多少天
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JS实现倒计时(时、分,秒)</title>
<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);
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(2015,8,29,'divdown1');}, interval);
</script>
</head>
这样就行了,直接复制就可以,样式自己添加css
阿里康康健康网
<body>
<div id="divdown1"></div>
</body>
</html>
C. JS倒计时代码,已有类似代码,求改编
只需要将var
startTime
=
(new
Date("August,8,2008,20:00,")).getTime();
=============》》》》》》改成
var
startTime
=
(new
Date("April,14,2009,20:00,")).getTime();
!!!!其中August是八月,April是四月!!!!!!!
我已经调试成功
结果为:★★★★★现在距北京奥运会还有:
264天
03:47:53★★★★★
若按linkzq所说改成var
startTime=
(new
Date(2009,4,14)).getTime();
则结果为★★★★★现在距北京奥运会还有:
已开始<
>★★★★★
D. js瀹炵幇璺濈2023骞5鏈1鏃ヨ繕鏈夊氬皯澶,灏忔椂,鍒,绉掔殑瀹炴椂鍊掕℃椂鏁堟灉锛
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>鍊掕℃椂</title>
</head>
<body>
<div id="countdown"></div>
<script>
// 瀹氫箟鍊掕℃椂鎴姝㈡椂闂
const endTime = new Date('2023-05-01 00:00:00').getTime();
// 姣忕掓洿鏂颁竴娆″掕℃椂
const countdown = setInterval(function() {
// 鑾峰彇褰撳墠鏃堕棿鎴
const nowTime = new Date().getTime();
// 璁$畻鏃堕棿宸锛堟绉掞級
const timeDiff = endTime - nowTime;
// 璁$畻鍓╀綑澶╂暟銆佸皬鏃舵暟銆佸垎閽熸暟銆佺掓暟
const days = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
const hours = Math.floor((timeDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((timeDiff % (1000 * 60)) / 1000);
// 灏嗗掕℃椂鏄剧ず鍦ㄩ〉闈涓
document.getElementById('countdown').innerHTML = '璺濈2023骞5鏈1鏃ヨ繕鏈夛細' + days + '澶 ' + hours + '灏忔椂 ' + minutes + '鍒 ' + seconds + '绉';
// 缁撴潫鍊掕℃椂
if (timeDiff < 0) {
clearInterval(countdown);
document.getElementById('countdown').innerHTML = '鍊掕℃椂宸茬粨鏉燂紒';
}
}, 1000);
</script>
</body>
</html>
E. 倒计时JS,到个位数的时候前面怎么加个0。倒计时天数。
if (daysRound<10)
{
daysRound="0"+daysRound;
}
还有类型转换的问题,用parseInt(),基本思路应该是这样
F. 求一个高考倒计时的js代码,加解释🙏
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1
-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<title>JS实现倒计时</title>
<scriptlanguage="javascript"type="text/javascript">
varinterval=1000;
functionShowCountDown(year,month,day,divname)
{
varnow=newDate();
varendDate=newDate(year,month-1,day);
varleftTime=endDate.getTime()-now.getTime();//剩余毫秒
varleftsecond=parseInt(leftTime/1000);
varday1=Math.floor(leftsecond/(60*60*24));//剩余天
varhour=Math.floor((leftsecond-day1*24*60*60)/3600);//剩余时
varminute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60);//剩余分
varsecond=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60);//剩余秒
varcc=document.getElementById(divname);
cc.innerHTML="距离高考"+year+"年"+month+"月"+day+"日还有:"+day1+"天"+hour+"小时"+minute+"分"+second
+"秒";//显示
}
window.setInterval(function(){ShowCountDown(2017,6,7,'divdown1');},interval);
</script>
</head>
<body>
<divid="divdown1"></div>
</body>
</html>
G. JS 5绉掑掕℃椂鐨勪唬鐮佹庝箞鍐欙紵鏃堕棿瑕佸疄鏃舵樉绀哄湪灞忓箷涓婄殑銆
<!DOCTYPEhtml>
<htmllang="en">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>js瀹炵幇鍊掕℃椂60绉掔殑绠鍗曚唬鐮(鎺ㄨ崘)</title>
<scripttype="text/javascript"src="js/jquery.js"></script>
</head>
<body>
<inputtype="button"id="btn"value="鍏嶈垂鑾峰彇楠岃瘉鐮"onclick="settime(this)"/>
<scripttype="text/javascript">
varcountdown=60;
functionsettime(val){
if(countdown==0){
val.removeAttribute("disabled");
val.value="鍏嶈垂鑾峰彇楠岃瘉鐮";
countdown=5;
}else{
val.setAttribute("disabled",true);
val.value="閲嶆柊鍙戦("+countdown+")";
countdown--;
setTimeout(function(){
settime(val)
},1000)
}
}
</script>
</body>
</html>
H. 求一个倒计时js代码,非常简单的
逻辑如下:
1、先判断两个时间的时间差,当然如果得到的时间是13位时间戳的话你需要转化一下
2、判断时间够一天显示天数,够一小时显示小时数
相关代码:
//获取时间,时间戳转换,不是则不转
varmydate1=newDate(parseInt(time1.replace("/Date(","").replace(")/","")));
varmydate2=newDate(parseInt(time2.replace("/Date(","").replace(")/","")));
//获取剩余秒数
vartimerc=dateDiff(mydate,'2015/05/1910:00:00')/1000;
functiondateDiff(date1,date2){
vardt1=newDate(Date.parse(date1));
vardt2=newDate(Date.parse(date2));
try{
returnMath.round((dt2.getTime()-dt1.getTime()));
}
catch(e){
returne.message;
}
}
//循环调用倒计时
functionadd(){//加时函数
--timerc;//时间变量自减1
varday=parseInt(timerc/86400);
varhour=parseInt((timerc%86400)/3600);
varmin=parseInt((timerc%3600)/60);
varsec=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+'秒');//写入秒数(两位)
}
elseif(hour>0){
$("#hour").html(hour+'时');//写入小时数
$("#min").html(min+'分');//写入分钟数
$("#sec").html(sec+'秒');//写入秒数(两位)
}
elseif(min>0){
$("#min").html(min+'分');//写入分钟数
$("#sec").html(sec+'秒');//写入秒数(两位)
}
elseif(sec!='00'){
$("#sec").html(sec+'秒');//写入秒数(两位)
}
else{
tiao(activity);returntrue;//时间到0调用函数
}
setTimeout("add()",1000);//设置1000毫秒以后执行一次本函数
};
望采纳!